Nuke command line render a file and use a python startupscript

When you start nuke you can pass it a .py file and it will execute this file on startup

Question first…
When issuing a command line render is it possible to feed it the startup py script along with the nuke script you want to render?

running nuke interactive:
nuke8.0.exe PyScript.py

running nuke command line render:
nuke8.0.exe -x nukeScript.nk

What I need is something like this, so nuke will launch in a shell import the python script then execute the nukescript
nuke8.0.exe PyScript.py -x nukeScript.nk

This does not work… it will launch an interactive session and import the PyScript.py then ignore -x and not open or render the nukeScript.nk file

Here is (a lot) more detail about my process…

I’ve begun building a python module to assist with my pipeline…
This consists of fetching information from a database, and handling write node outputs automatically based on the nuke script name.

This all works well inside an interactive session of nuke, I have a python script that sets env vars and launches nuke with a startup py script. This startupscript sets paths, and imports my module… and the important part my module imports the nuke module so I can get node information within the nuke script.

Launch nuke script sudo code::


os.environ["PROJECT_NAME"] = "blahBlahBlah"          # Later scripts use this info to get data from the database
os.system(nuke startupscript.py)                     # This launches nuke and makes it run startupscript.py when it opens

startupscript.py sudo code::


import sys
import nuke
sys.path.append("pipelinepath")                             # Add pipeline path (this is dynamic based on user machine)
nuke.pluginAddPath("somePath")                              # Add paths for nuke to find scripts, gizmos etc..

import pipeline.nuke                                        # Make my module available for use within nuke

pipeline.nuke.py sudo code::


import nuke                                                                               # This module needs the nuke module to read nuke data

def outputFromFilename()
    scriptName = nuke.root()['name'].getValue()                                           # Get nuke script name
    output = pipelineFunction()                                                           # Run pipeline functions to determine output
    nuke.thisNode().knob("beforeRender").setValue('pipeline.nuke.makeOutputFolder()')     # Make sure output directory exists before rendering since nuke is too stupid to make if for you.
    return output

So in the nuke script, the write node filename would be set to
[python pipeline.nuke.outputFromFilename()]

All of this requires that my scripts can “import nuke” module
Adding the nuke/plugins path to sys.path allows me to import nuke… but it fails on the line
from _nuke import * within nuke/plugins/nuke/init.py

My modules live outside the nuke folder (network location), so they are version agnostic and don’t require every new user to install plugins / scripts into their local nuke folder… so i’m not interested in a solution involving copying scripts to local machines.

I know you can start python from within the nuke folder and import nuke that way, perhaps this is a solution but I get a license error when trying this (I only have an interactive license at the moment and don’t know how to trigger the use of an interactive license)

Thanks for reading
Any help is appreciated.

I’ll try and read things in more depth and reply if i find the time later on. In regards to the licensing question check the licensing part of the import nuke chapter in the dev guide:

http://docs.thefoundry.co.uk/nuke/80/pythondevguide/nuke_as_python_module.html#licensing

You can use an env variable to enforce GUI license use.

Cheers,
Thorsten

it’s been quite a while that i did python-nuke stuff. But what we did back then was to start nuke via command-line, pass it our main-python-script as as the first argument, and the nuke file to operate on as the second argument.
The idea is that everything that is passed as additional arguments will be in the sys.argv list when you enter the python script you passed to nuke. So you can tell nuke to “scriptOpen(…)” the nuke file from within your main-python-script.

that’s what i remember, maybe it helps :wink:

Sounds like that might work, when I get a break from my artist duties I’ll give that a shot.
Thanks.