Simple problem. I want to change the parent of LayerA to GroupB. The member "parent" of layer is read only, and I can't use pdb.gimp_image_insert_layer because the layer already has been added to image. I also tried removing it first by gimp_image_remove_layer, and it also doesn't work.
Asked
Active
Viewed 96 times
0
-
"and it also doesn't work" - what happens? How is that different from what is supposed to happen? – Karl Knechtel Feb 05 '22 at 15:56
-
If I use "gimp_image_remove_layer" and then "gimp_image_insert_layer" this is what happens: **Calling error for procedure 'gimp-image-insert-layer': Procedure 'gimp-image-insert-layer' has been called with an invalid ID for argument 'layer'. Most likely a plug-in is trying to work on a layer that doesn't exist any longer.** As for "How is that different from what is supposed to happen?", I don't understand the question. I'm just experimenting, I don't know how Gimp functions work internally. I thought that maybe it would let me use remove and then insert functions, but alas. – krokots Feb 05 '22 at 17:22
1 Answers
1
I cannot find an API for this in Python. Using image.remove_layer() deletes the layer so it cannot be re-inserted, so the best I can think of is to copy the layer using something like this:
def moveLayer(image,layer,group,position):
layerName=layer.name
layerCopy=layer.copy()
image.remove_layer(layer)
layerCopy.name=layerName # Can't have two layers with same name
image.insert_layer(layerCopy,group,position)
return layerCopy # this one has a new ID
This said, I've written many Python scripts and never needed to change a layer parent, so maybe there is a way to avoid doing this...

xenoid
- 8,396
- 3
- 23
- 49
-
Thanks, that will do. By the way, is there any recent documentation on gimp python? I just mostly use "browse" in gimp python console, and dir() function. – krokots Feb 06 '22 at 10:27
-
So do I... there is also [this](https://www.gimp.org/docs/python/) but not that complete. – xenoid Feb 06 '22 at 10:54