Nuke EnumerationPulldown

Nuke EnumerationPulldown

I was trying to create a simple panel with a dropdown menu, and had some trouble with nuke panel.addEnumerationPulldown. Here’s the code I was typing:
opts = ('on', 'from auto-localize path', 'off')
p = nuke.Panel('Change read localization')
p.addEnumerationPulldown('Set localization policy', opts)

I expected the panel to give me a dropdown list of on, from auto-localize path and off. Instead it treated everything after a space a different entry, which gives me this ridiculous result.

 

 

 

 

After some research I found a solution from Foundry Community, which uses re module to solve the issue. Here’s the finished code:

opts = ('on', re.escape('from auto-localize path'), 'off')
reOpts = ','.join(opts)
policyOpts = reOpts.replace(',',' ')
p = nuke.Panel('Change read localization')
p.addEnumerationPulldown('Set localization policy', policyOpts)

 

 

 

 

The post from community also mentioned the use of nukescripts.PythonPanel instead of nuke.Panel module, which could avoid this problem. But for this simple tool this will do, and nukescripts.PythonPanel is up on my list of investigation!

 

Note: There’s an update on using nukescripts.PythonPanel now here.

One thought on “Nuke EnumerationPulldown

Leave a Reply

Your email address will not be published. Required fields are marked *