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

solved] How to mimic File > Open as Layers from within a python script

Tue Jun 20, 2017 6:10 am

Inside my python script these four lines of code open two .xcf files which are displayed in seperate windows, how do i code it so as to open both images into a single stack in the same window (as in File > Open as Layers)

image_1 = pdb.gimp_xcf_load(0,"C:\\Users\\SteveMi\\.gimp-2.8\\plug-ins\\red.xcf", "red.xcf")
display = pdb.gimp_display_new(image_1)

image_2 = pdb.gimp_xcf_load(0,"C:\\Users\\SteveMi\\.gimp-2.8\\plug-ins\\green.xcf", "green.xcf")
display = pdb.gimp_display_new(image_2)

TIA

steve

Re: How to mimic, File > Open as Layers from within a python script

Tue Jun 20, 2017 6:45 am

The procedure browser is your friend:
Untitled.png
Untitled.png (37.94 KiB) Viewed 3592 times

Re: How to mimic, File > Open as Layers from within a python script

Tue Jun 20, 2017 6:53 am

You can also copy the layers between opened images, something like:

Code:
for layer in reversed(image2.layers):
    layerCopy=pdb.gimp_layer_new_from_drawable(layer,image1)
    image1.add_layer(layerCopy,0);


Useful if you don't intend to keep all the layers, or if you reposition them.

Re: How to mimic, File > Open as Layers from within a python script

Tue Jun 20, 2017 8:25 am

Thanks paynekj, this puts me on the right track. I do use the PB but sometimes am unsure which of the similar procedures to use

Thanks ofnuts, this is great and helps a lot, though you do drop a point for the missing underscores ;) , first run nothing happened but its ok now

steve

Re: How to mimic, File > Open as Layers from within a python script

Tue Jun 20, 2017 9:35 am

Which missing underscores? Copy/pasted from my editor, and copy/pasted to Gimp's Python console to check.

Re: How to mimic, File > Open as Layers from within a python script

Tue Jun 20, 2017 9:58 am

ofnuts wrote:Which missing underscores? Copy/pasted from my editor, and copy/pasted to Gimp's Python console to check.

Ah I see, my bad :oops: , sorry. I copied your code straight into my python script and ran it, after nothing happened I noticed you had used image2 whereas I had used image_2

steve
Post a reply