Q100538: How to set default values for knobs and preferences stored in uistate.ini

Follow


SUMMARY

This article will explain how you can access and change certain settings and preferences that are saved in your uistate.ini file.

MORE INFORMATION

Nuke 

In Nuke, the values stored in the uistate.ini can be changed with PySide2’s QSettings class. The following code is an example of this:

from PySide2.QtCore import QSettings
settings = QSettings("/path/to/.nuke/uistate.ini", QSettings.IniFormat) 
settings.setValue("header/setting", "newValue")

Where:

  • "/path/to/.nuke/uistate.ini" is the full path to your uistate.ini file.

  • "header/setting" is the name of the setting that you want to change the value of, and the heading it is stored under.

  • "newValue" is the value you want the setting to be changed to.

A simple example of this would be to turn on the File Browser preview. You can run the following code in the Script Editor to see the effect immediately:

from PySide2.QtCore import QSettings
import os
settings = QSettings(os.path.expanduser("~")+"/.nuke/uistate.ini", QSettings.IniFormat)
settings.setValue("FileBrowser/preview", "true")

However, if the setting is stored under the ‘General’ header, you do not need to give the header name in settings.setValue() and you can just use the settings name on its own. For example:

from PySide2.QtCore import QSettings
import os
settings = QSettings(os.path.expanduser("~")+"/.nuke/uistate.ini", QSettings.IniFormat)
settings.setValue("submitUsageStatistics", "true")

To run this code on startup, you can add it to your menu.py or init.py file, which is stored in your .nuke directory

 

Hiero/Nuke Studio 

In Nuke Studio and Hiero, this is also directly accessible via Python by using the ApplicationSettings() method. The arguments given for ApplicationSettings() should look like the following:

hiero.core.ApplicationSettings().setValue("header/setting", "new value")

Then, for example, you could run the following line of code in the Script Editor to change the autosave interval to 300 seconds:

import hiero
hiero.core.ApplicationSettings().setValue("autosave/intervalSecs", "300")

Again, if the setting is stored under the ‘General’ header, you do not need to give the header name in the first argument and you can just use the settings name on its own. For example:

import hiero
hiero.core.ApplicationSettings().setValue("quickTimeSubProcessCount", "2")

To run this code on startup in Nuke Studio/Hiero, you can add it to a Python file inside the following directory: ~/.nuke/Python/Startup

 

FURTHER READING

To find the name of the setting that you wish to change, you can open your uistate.ini file in a text editor. In the case of the force project autosave after setting, you can see that it is saved in the uistate.ini under the [autosave] header and is named intervalSecs:

mceclip1.png

    We're sorry to hear that

    Please tell us why