Gimp 2.99 Gradient mapping

I am trying to port a Python plugin that I use from Gimp 2.10 to Gimp 2.99.
In Gimp 2.10 you simply select the gradient you want by setting the context and then call
pdb.plug_in_gradmap(image, actlayer)
where actlayer is the active layer.
In Gimp 2.99 the syntax from the pdb browser is more complex but essentailly does the same thing
procedure = Gimp.get_pdb().lookup_procedure(‘plug-in-gradmap’)
mconfig = procedure.create_config()
mconfig.set_property(‘run-mode’, Gimp.RunMode.INTERACTIVE)
mconfig.set_property(‘image’, image)
mconfig.set_property(‘num-drawables’, 2)
mconfig.set_property(‘drawables’, actlayer)
result = procedure.run(mconfig);
success = result.index(0)
but this gives an error
TypeError: could not convert < Gimp.Layer object at 0x710050069200(GimpLayer at 0x55d0dabc07e0) > to type ‘GimpObjectArray’ when setting property
‘GimpProcedureConfig-plug-in-gradmap.drawables’
I have tried all sorts of ways to reference the layer but they all just give the same layer object which is rejected. Does anyone have any idea how I can get the correct object?

drawables should be a list since it can be more than one layer. So [actlayer]. Note that you set num-drawables to 2, meaning that you told there will be 2 layers in the drawables list.

Also note that the API has changed since 2.99.18 and the drawables including the count have been removed. You can use separate functions to get the selected layers or all layers.

1 Like

You can see how it’s done in 2.99.18 here: images/export-splash.py · be37d3fee97be70bb5856f0c8c6d3e756f71f2ff · GNOME / gimp-data · GitLab

As @jboerema said though, those will be removed for the 3.0 release. You might add a comment noting this for yourself until it’s out.

Thanks very much. Defining an ObjectArray as in the code snippet works perfectly. I did search for Gimp.ObjectArray but without success. I think I will suspend work on this plugin if this is changing so drastically because the plugin uses gradient mapping several times. A note has been added to the code ported so far!

1 Like