PDA

View Full Version : personal menu for opening script templates



arikitraun
March 16th, 2010, 05:41 AM
Hi!
I have several .nk files that I want to use as templates.
I want to make a python script with my own list menu with a button for every template, so when I push on the desired button a new nuke opens with the selected template.
What's the best way for doing it into nuke?

Thank you very much!

arikitraun
March 17th, 2010, 05:47 AM
Ok,
I think I've found a solution that opens a nuke script from an already opened nuke window:

import subprocess
subprocess.Popen([<nukeExecutablePath>, <filePath>], shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

alkali
March 17th, 2010, 11:39 AM
subprocess.call is a lighter (and cleaner) way to call another program if you need to be returning output codes from it.

arikitraun
March 17th, 2010, 01:08 PM
I'll try with this method,
Thank you very much alkali!

alkali
March 17th, 2010, 01:11 PM
Just to clarify, you're intentionally trying to open these templates in a new Nuke process instance, correct? As opposed to opening the templates in a new workspace under the currently running Nuke process?

arikitraun
March 17th, 2010, 01:13 PM
Yes, initially I was thinking on a new nuke process instance, but don't know if the other option will be better...

alkali
March 18th, 2010, 11:57 AM
My first thought is it would be better to keep things sandboxed in the same Nuke process to avoid having two different instances fighting for RAM (if your comps get heavy). This would also make it much easier to set up the menu item. However, separating the comps into different instances would keep the others alive if one decided to crash, so there are tradeoffs.

arikitraun
March 18th, 2010, 12:09 PM
Then I preffer the choice of individual instances, I need to manage the closing individually.
...so should I keep on using "subprocess.Popen()" then?

Thanks!

tinitron
March 18th, 2010, 06:19 PM
I am sure nuke is already able to do that.

When I remember correctly there is nuke.scriptOpen(filename) to open the script in a new instance and nuke.scriptAdd(filename) to load it into the current script. No need to do system calls.

You can easily look this up in the python reference. Also nuke's init.py and menu.py are a great source to look for things like this. You could for example look what the menu File -> Open Script is calling as it is exactly doing what you are looking for except that there is a fileselect dialog to select the script to open.

arikitraun
March 18th, 2010, 06:53 PM
Thank you very much tinitron!
I think nuke.scriptOpen(filename) is just what I was looking for, with transparency of creating processes or intances.