5

I can't seem to find any methods for adding a Group Layer to another Group Layer anywhere in the python-fu interface.

I've tried to find methods on the Gimp.Layer objects as well but with no luck.

How do I add a group layer to another group layer with python-fu?

Hannele
  • 9,301
  • 6
  • 48
  • 68
Larpon
  • 812
  • 6
  • 19
  • 1
    This questin is on-topic - it asks about the programing API for GIMP, and as can be seen on the answer, asks for something thaqt is not obvious and is poorly documented. – jsbueno Dec 18 '12 at 11:25
  • Cheers I've rephrased it a bit (I'm new here - first question!) – Larpon Dec 19 '12 at 15:54

1 Answers1

6

The support to layer groups on Python-fu was added on the last minutes before 2.8 release, and is rather incomplete.

So, the only way to create a proper layer group in GIMP 2.8 is to use the pdb call:

group = pdb.gimp_layer_group_new(img)
group.name = "my group"

(Using the img.GroupLayer call is buggy on gimp 2.8 - should be the way to go in the future)

Once you have your group, you can insert it anywhere on the image using a

pdb.gimp_image_insert_layer(<img>, <layer>, <parent>, <position>)

Like in:

>>> img = gimp.Image(640, 480, RGB)
>>> pdb.gimp_display_new(img)
<display>
>>> parent_group = pdb.gimp_layer_group_new(img)
>>> child_group_1 = pdb.gimp_layer_group_new(img)
>>> child_group_2 = pdb.gimp_layer_group_new(img)
>>> grand_child_group = pdb.gimp_layer_group_new(img)
>>> img.add_layer(parent_group, 0)
>>> pdb.gimp_image_insert_layer(img, child_group_1, parent_group,0)
>>> pdb.gimp_image_insert_layer(img, child_group_2, parent_group,1)
>>> pdb.gimp_image_insert_layer(img, grand_child_group, child_group_1,0)
>>> l1 = gimp.Layer(img, "test", 320,240)
>>> pdb.gimp_image_insert_layer(img,l1, grand_child_group,0)

So, indeed, there is this extreme API asymmetry, in which you add layers and groups to the image through an "add_layer" method on the parent, but have to add either to a layer group, you have to go troguh the pdb.gimp_image_insert_layer call.

update (Feb/2015) - The bug for gimp.GroupLayer() is fixed in GIMP's git and it will work properly from GIMP 2.8.16 onward. Now all one has to do to add a new group layer is:

>>> g = gimp.GroupLayer(img)
>>> pdb.gimp_image_insert_layer(img, g, None, 0)
jsbueno
  • 99,910
  • 10
  • 151
  • 209
  • 2
    Thank you very much for clearing that out for me - I must've missed the pdb.gimp_image_insert_layer call completely. Though I know it's not the intended use - I use the GIMP with python-fu as a scene editor (more like an object placement editor actually) for an adventure game engine. I can quickly set up touchable areas (channels with parasites) and objects with representative graphics (layers with parasites) on scenes. Import and export of scene xml files make it much faster to place and correct objects in the game :) Thanks to your hard work I've been saving a lot of time! – Larpon Dec 17 '12 at 13:36