Editing the Shelf Preferences with Python
Below are example Python scripts to modify the Windows Registry in order to manipulate Shelf paths.
Adding a Shelf Path
Adding Shelf path for Substance Paint in the Windows registry requires to check which one exist already in order to increment the list with a new one. The following code add in the Windows Registry a new shelf path after checking what is the current number of path already defined.
import winreg
RegistryKeyName = "Software\\Allegorithmic\\Substance Painter\\Shelf\\pathInfos"
ShelfName = "myshelf" #Needs to be lowercase
ShelfPath = "C:/Temp"
ShelfStatus = "false" #false = not disabled
try:
RegConnection = winreg.ConnectRegistry( None, winreg.HKEY_CURRENT_USER )
#Open registry key
Key = winreg.OpenKey( RegConnection, RegistryKeyName, winreg.KEY_READ )
SubKeyCount = winreg.QueryInfoKey( Key )[0]
#Iterate over each sub-key to find the biggest Shelf number
ShelfNumber = 0
for x in range(SubKeyCount) :
SubKeyName = winreg.EnumKey(Key, x)
if int(SubKeyName) > ShelfNumber :
ShelfNumber = int(SubKeyName)
#Create the new Key and add its values
ShelfNumber += 1
NewKey = winreg.CreateKey( Key, str( ShelfNumber ) )
winreg.SetValueEx( NewKey, "disabled", 0, winreg.REG_SZ, ShelfStatus)
winreg.SetValueEx( NewKey, "name", 0, winreg.REG_SZ, ShelfName)
winreg.SetValueEx( NewKey, "path", 0, winreg.REG_SZ, ShelfPath)
#Finish
NewKey.Close()
Key.Close()
except Exception as e :
print( e )
After adding a shelf path, make sure to increment as well the "size" value inside the "pathInfos" registry key.
Disabling or Enabling a Shelf Path
Shelf path created in Substance Painter can be removed but also disabled. This is mostly true for the default Shelf shipped with Substance Painter which can only be disabled. The following code parse the Windows Registry and disable the default shelf (named "allegorithmic").
import winreg
RegistryKeyName = "Software\\Allegorithmic\\Substance Painter\\Shelf\\pathInfos"
try:
RegConnection = winreg.ConnectRegistry( None, winreg.HKEY_CURRENT_USER )
#Open registry key
Key = winreg.OpenKey( RegConnection, RegistryKeyName, winreg.KEY_READ )
SubKeyCount = winreg.QueryInfoKey( Key )[0]
#Iterate over each sub-key
for x in range(SubKeyCount) :
SubKeyName = winreg.EnumKey(Key, x)
SubKey = winreg.OpenKey( RegConnection,
RegistryKeyName + "\\" + SubKeyName,
winreg.KEY_READ )
SubKeyValueCount = winreg.QueryInfoKey( SubKey )[1]
#Read subkey values
Values = []
for i in range( SubKeyValueCount ) :
Values.append( winreg.EnumValue( SubKey, i ) )
#Note : Values is a table of tuples
FoundKey = False
for Value in Values :
if Value[0] == "name" :
if Value[1] == "allegorithmic" :
FoundKey = True
SubKey.Close()
#Found the path ? Then we edit the Key
if FoundKey :
print( " - Editing Windows Registry" )
#Re-Open key in edition mode
SubKey = winreg.OpenKey( winreg.HKEY_CURRENT_USER,
RegistryKeyName + "\\" + SubKeyName,
0,
winreg.KEY_SET_VALUE )
#Assign new value
winreg.SetValueEx(SubKey, "disabled", 0, 1, "true" ) #use "false" to Enable that shelf path
SubKey.Close()
#Finish
Key.Close()
except Exception as e :
print( e )