New module instance using lua

Hello,

Is there a way to create a new instance of a darkroom module in darktable using lua?

My first suspect would be darktable.gui.action, but unfortunately the documentation is scarce for this function and I cannot figure out which element or effect could do the trick.

Greetings,
Christoph

Here’s an example

dt.gui.action("iop/diffuse", 0, "instance", "new", 1.0)

The easiest way to find the parameters to use for dt.gui.action is to create a shortcut that does what you want (selecting the correct element and effect from their dropdowns in the shortcuts dialog or preferences tab), then select the shortcut and press ctrl+c. This puts the lua command on the clipboard so you can paste it in your script editor.

You can also see the lua command for a visible widget (for example the module’s “instance” button) in its tooltip when you switch on shortcut mapping mode and then a long right-click copies it. But that is only useful for default elements/effects; it doesn’t offer a way to find all available options.

3 Likes

Thanks a lot for your reply @dterrahe .

That’s a very useful feature, but unfortunately, when hovering over the instance button in shortcut mapping mode, only dt.gui.action("iop/exposure", "instance", "show", 1.000, 0) is shown as example, not the other possible actions.

Thank you @wpferguson, works like a charm.

Is there also a way to rename the new instance? I got as far as dt.gui.action("iop/exposure", 0, "instance", "rename", 1), which makes the instance’s name editable, but I still need to put the new name by hand.

Try including the new name as another argument after rename, i.e. dt.gui.action("iop/exposure", 0, "instance", "rename", "new name", 1)

Hello @wpferguson,

Thanks for the reply, but it seems darktable doesn’t like it:

LUA ERROR : bad argument #5 to '?' (number expected, got string)

It was a guess. @dterrahe would know if there’s a way

Not using dt.gui.action, no.

1 Like

Well, bad luck, but thanks nevertheless.