Q100142: How to execute Hiero Python code in Nuke Studio and Hiero on startup

Follow

SUMMARY

This article explains where to place a script containing Hiero specific Python commands to ensure they will be executed correctly in Nuke Studio and Hiero on startup.

 

MORE INFORMATION

To run Hiero custom Python code in Nuke Studio or Hiero on startup, you will need to add your code to one the following locations:

~/.nuke/Python/Startup

~/.nuke/Python/StartupUI

This is the Hiero file structure for Python customizations.  

Please note that the above folders do not exist by default and will need to be created manually on first use inside your .nuke directory. More details on accessing your .nuke directory can be found in this article: Q100048: Nuke Directory Locations

The difference between the Startup and StartupUI folders is the order they are scanned in. All of your Startup folders are searched first, and then all of your StartupUI folders. So when deciding which folder to save your code in, you may need to consider any dependencies that your plugins may rely on.

 

NEXT STEPS

  1. Create a new text file and add your custom Hiero Python code to it.

  2. Save the file to ~/.nuke/Python/Startup/<script_name>.py or ~/.nuke/Python/Startup/<script_name>.py and make sure file extensions are shown in your file browser when you do this, to verify that the file extension is .py and not .txt, or different.

  3. At this point you might see a warning message telling you that you are about to change the file type which might make the file unusable. Ignore this as the extension .py is expected and will be recognized by Nuke Studio and Hiero. 

NOTE: Adding any Python code for Hiero in your ~/.nuke/menu.py or ~/.nuke/init.py will result in the following error when launching Nuke/NukeX/Nuke Studio: ImportError: No module named _fnpython

This error occurs because _fnpython is a private module which is created in the application code (similar to _nuke). The reason this doesn't work is that init.py is executed before Hiero's Python modules are properly initialized. This error has been reported as a bug, which you can follow and subscribe for updates via the URL below:

ID 154593 - Adding "import hiero" to the init.py or menu.py files in your .nuke directory prevents Nuke from running


Terminal Mode:

Unfortunately, it is not currently possible to run Hiero or Nuke Studio in terminal mode, however, an internal feature request has been logged for implementing this functionality, which can be referenced as:

ID 138339 - Implement a Headless/Terminal mode for Hiero/Nuke Studio

 

FURTHER READING

More information about executing Hiero Python code on startup can be found in the Environment Setup section of the Hiero Python Developer Guide.

    We're sorry to hear that

    Please tell us why