Q100487: How to refresh Task Presets within an active Nuke Studio/Hiero session

Follow

SUMMARY

This article will outline how you can refresh your Task Presets within an active Nuke Studio/Hiero session.

 

MORE INFORMATION

By default, Nuke Studio and Hiero will only refresh its Task Presets once the application has been restarted. However, by using Python, you are able to reload pre-existing Task Presets saved in a shared location or add new ones to your Task Presets directory on the fly. The following is a simple example of how this can be achieved:

#remove all presets that are currently loaded as this prevents them being duplicated
R = hiero.exporters.registry
presetNamesToRemove = hiero.exporters.registry.processorPresetNames()

for presetName in presetNamesToRemove:
R.removeProcessorPreset(presetName)

#reload the presets in again
#where ~/.nuke/TaskPresets/15.1/ is the path to your Export Presets
R.loadPresets("~/.nuke/TaskPresets/15.1") #change this path to your Export Presets directory

 The above code works by simply finding a list of currently loaded Task Presets and removes them, this will stop them being duplicated when they are loaded again with hiero.exporters.registry.loadPresets()

For the above code to work as it is, it would need to be run in the Script Editor every time you wish to refresh your Task Presets. However, you could build upon this by wrapping the code up into a button or widget. For example, the following code will add this to the right-click menu:

import hiero.core, hiero.ui, nuke
from PySide2 import QtWidgets
from PySide2.QtWidgets import QMessageBox
from hiero.core import events
import glob, os

class refreshTaskPresets(QtWidgets.QAction):
def __init__(self, event):
QtWidgets.QAction.__init__(self, "", None)
self.event = event
self.triggered.connect(self.doit)

def doit(self):

presetPath = os.path.expanduser("~")+"/.nuke/TaskPresets/15.1" #change this path to your Export Presets directory

#checking if the path given path contains xml files
if len(glob.glob(presetPath+"/*/*/*.xml")) > 1:

#remove all presets that are currently loaded as this prevents them being duplicated
R = hiero.exporters.registry

presetNamesToRemove = hiero.exporters.registry.processorPresetNames()

for presetName in presetNamesToRemove:
R.removeProcessorPreset(presetName)

#reload the presets in again
R.loadPresets(presetPath)

#if the path is invalid, a warning error will appear
else:
msgBox = QMessageBox()
msgBox.setText("Task Presets could not be refreshed. Please check if the path set in refreshTaskPresets.py is valid: "+presetPath)
msgBox.exec_()


def AddActionToMenu(event):
menu = event.menu
menu.addAction("Refresh Task Presets", lambda: refreshTaskPresets(event).trigger())

events.registerInterest((events.EventType.kShowContextMenu), AddActionToMenu)

This script works by adding the first example code as a QAction to a QWidget. It then checks if the path set in the script by the user (presetPath) contains xml files and, if it does, the Task Presets are refreshed, however, if it does not, an error message is displayed to warn the user.

You can add this script into your ~/.nuke/Python/Startup directory and you should now be able to see a Refresh Task Presets option on your right click menu. For example, if you right click on the Timeline:

 

FURTHER READING

The following article contains more information about where to find your Task Preset XML files: Q100294: Directory location for Nuke Studio and Hiero export presets

You can find more information about using Python startup scripts in Nuke Studio and Hiero in the following article: Q100142: How to execute Hiero Python code in NukeStudio on startup

More information about the glob module can be found in Python’s documentation.

You can find some information about working with PySide2 in Nuke here, however, you will need to refer to the Qt for Python Documentation for further information.

    We're sorry to hear that

    Please tell us why