GIMP Chat
http://gimpchat.com/

solved] How to mimic File > Open as Layers from within a python script
http://gimpchat.com/viewtopic.php?f=9&t=15680
Page 1 of 1

Author:  Steve [ Tue Jun 20, 2017 6:10 am ]
Post subject:  solved] How to mimic File > Open as Layers from within a python script

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

Author:  paynekj [ Tue Jun 20, 2017 6:45 am ]
Post subject:  Re: How to mimic, File > Open as Layers from within a python script

The procedure browser is your friend:
Attachment:
Untitled.png
Untitled.png [ 37.94 KiB | Viewed 3588 times ]

Author:  ofnuts [ Tue Jun 20, 2017 6:53 am ]
Post subject:  Re: How to mimic, File > Open as Layers from within a python script

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

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.

Author:  Steve [ Tue Jun 20, 2017 8:25 am ]
Post subject:  Re: How to mimic, File > Open as Layers from within a python script

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

Author:  ofnuts [ Tue Jun 20, 2017 9:35 am ]
Post subject:  Re: How to mimic, File > Open as Layers from within a python script

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

Author:  Steve [ Tue Jun 20, 2017 9:58 am ]
Post subject:  Re: How to mimic, File > Open as Layers from within a python script

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

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/