Enable/Disable RenderPasses with EditScope through python script/button

59 views
Skip to first unread message

Riccardo Cecchinato

unread,
Aug 19, 2025, 11:55:28 AMAug 19
to gaffer-dev
Hello dear Gaffer dev!

I was wondering which is the cleanest way to enable/disable RenderPasses - in an EditScope - through a button driven by python scripting.

As I would do by hand thanks to the Render Passes Editor, once focused on said EditScope, the operations should be:

- Target/activate the specific EditScope ("Edit targets > EditScopeName")

- Enable the [already existing/created] RenderPasses, for example those whom names compare in a list containing strings (eg. "CHARS_ALL", "SETS_ALL", "SETS_MASK")

- Potentially disable all the RenderPasses not present in said list

- Release the EditScope (as when we go back to "Edit targets > source")

Thanks in advance for your always unvaluable help,
Riccardo

John Haddon

unread,
Aug 20, 2025, 3:55:45 AMAug 20
to gaffe...@googlegroups.com
Hi Riccardo,

The API you are looking for is in the EditScopeAlgo namespace :

https://github.com/GafferHQ/gaffer/blob/main/include/GafferScene/EditScopeAlgo.h#L158-L161

Your first and last steps are actually unnecessary when using the API - the "current EditScope" is just a UI concept, and in the API you instead pass the EditScope directly as an argument. The enabledness of a render pass is controlled using the `renderPass:enabled` option, so to ensure a series of passes are enabled in a particular scope, you could do this :

```

for renderPass in [ "CHARS_ALL", "SETS_ALL", "SETS_MASK" ] :

    tweakPlug = GafferScene.EditScopeAlgo.acquireRenderPassOptionEdit( editScope, renderPass, "renderPass:enabled" )
    tweakPlug["enabled"].setValue( True )
    tweakPlug["value"].setValue( True )
```
You can get a list of all render passes at a certain point in the graph by querying the `renderPass:names` option like so :

node['out'].globals()["option:renderPass:names"]


You could use that to iterate all the render passes and disable the others.

Hope that helps...
Cheers...
John



--
You received this message because you are subscribed to the Google Groups "gaffer-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gaffer-dev+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/gaffer-dev/ac560761-b416-4723-8605-564d3fbb1c38n%40googlegroups.com.

Riccardo Cecchinato

unread,
Aug 20, 2025, 11:31:06 AMAug 20
to gaffer-dev
John,
thank you so much for the quick and informative reply, this will help for sure!

Best,
Riccardo

Riccardo Cecchinato

unread,
Aug 22, 2025, 11:04:35 AMAug 22
to gaffer-dev
Hello John!
I am acquiring the list of renderPasses to enable and those to disable, and cycling through two dedicated "for loop" to enable and disable, but It seems like I cannot do the latter.

Could you please confirm that the correct method to disable a render pass in an EditScope is:

tweakPlug = GafferScene.EditScopeAlgo.acquireRenderPassOptionEdit( editScope, renderPass, "renderPass:enabled" )

tweakPlug["enabled"].setValue( False )

tweakPlug["value"].setValue( False )


Thanks in advance for your support!

Riccardo


Riccardo Cecchinato

unread,
Aug 22, 2025, 11:16:54 AMAug 22
to gaffer-dev
To give a little bit more context, it seems like ( False ) enables as well the tweakPlug["enabled"]

Riccardo Cecchinato

unread,
Aug 22, 2025, 11:33:25 AMAug 22
to gaffer-dev
John,
nevermind, I just realised the correct form for disabling is to keep the plug enabled :

tweakPlug = GafferScene.EditScopeAlgo.acquireRenderPassOptionEdit( editScope, renderPass, "renderPass:enabled" )

tweakPlug["enabled"].setValue( True )

tweakPlug["value"].setValue( False )


Sorry for bothering you again, it works like a charm!!


Best,

Riccardo


Riccardo Cecchinato

unread,
Aug 28, 2025, 12:33:50 PM (12 days ago) Aug 28
to gaffer-dev
Hello dear devs!

Sorry for reviving this with an off-topic question, but I guessed it was better to avoid creating a whole new topic for such a small thing.

Given a node selection, is there a python command available to obtain the same automatic node alignment we get with "CTRL+L" hotkey?

Thank you in advance, as usual!

Riccardo

John Haddon

unread,
Aug 28, 2025, 1:10:14 PM (12 days ago) Aug 28
to gaffe...@googlegroups.com
On Thu, Aug 28, 2025 at 5:33 PM Riccardo Cecchinato <rcecc...@stimstudio.com> wrote:
Given a node selection, is there a python command available to obtain the same automatic node alignment we get with "CTRL+L" hotkey?

There is, but with a bit of a caveat. You can see the code that `Ctrl +L` runs here :  https://github.com/GafferHQ/gaffer/blob/main/python/GafferUI/EditMenu.py#L323-L330.

The call to `layoutNodes()` is what you want, but as it's a method of a component of the GraphEditor, you can only really call it if you can find a GraphEditor. At one point, we had the thought that potentially different editors could have different layouts for the same node, hence the two were tied together. But in practice that hasn't happened and we're just left with an annoying coupling in the API...


Riccardo Cecchinato

unread,
Aug 29, 2025, 5:58:49 AM (12 days ago) Aug 29
to gaffer-dev
John,
Thanks a lot for the reply! It is exactly what I was looking for.

However, I am able to make it work via script editor, but it seems like it does not work via node (with Py button). Could this be related to the caveat you were pointing out?
Or maybe it's just me not setting the Py button up properly.

NB. Actually, it does not work if I load my Py code in the PY button through "import" plus its def() call.
If I copy paste the entire code straight into the Py button code input, it does work. 

Thanks a million!
Riccardo
Reply all
Reply to author
Forward
0 new messages