Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

Python - How to set text on layer without loosing formating

Wed May 17, 2017 1:34 pm

I have realy simple script:
Code:
def replace(image, drawable):
    layers = image.layers
    for layer in layers:
        if pdb.gimp_drawable_is_text_layer(layer):
            pdb.gimp_text_layer_set_text(layer,'aaa')


It works. After this script on every text layer is text 'aaa' but my settings of font size and color disappear (after script text is always black and font size = 18).

What is wrong?

Re: Python - How to set text on layer without loosing formating

Wed May 17, 2017 2:28 pm

Which gimp are you using.
It works on mine (the formatting, font and font size stays the same).
I am on Gimp 2.8.20

PS: I think I know what you did. I recreated your problem. You created text layers, then instead of setting/changing font options using tool options you selected the text and changed the font and font size for that text. So that doesn't work because the text layer itself still has the font and font size of default Sans 18. So when you set the text the format is lost because that text layer is still Sans 18. To make it work, you have to change font settings in Tool options then create text that way, you're setting the text layer's font and fontsize and not just for the text you've created. I hope i am explaining that right.
Post a reply