Set an optionVar
import maya.cmds as cmds
option_var_name = "myOptionVar"
option_var_value = 42
# Set the optionVar
cmds.optionVar(iv=(option_var_name, option_var_value))
Get the value of an optionVar:
import maya.cmds as cmds
option_var_name = "myOptionVar"
# Get the optionVar value
option_var_value = cmds.optionVar(q=option_var_name)
print(option_var_value) # Output: 42
Check if an optionVar exists:
import maya.cmds as cmds
option_var_name = "myOptionVar"
# Check if the optionVar exists
if cmds.optionVar(exists=option_var_name):
option_var_value = cmds.optionVar(q=option_var_name)
print(option_var_value)
else:
print("OptionVar does not exist.")
Delete an optionVar:
import maya.cmds as cmds
option_var_name = "myOptionVar"
# Delete the optionVar
if cmds.optionVar(exists=option_var_name):
cmds.optionVar(remove=option_var_name)
print("OptionVar deleted.")
else:
print("OptionVar does not exist.")
String Array
import maya.cmds as cmds
def SetOptionVarStringArr(option_var_name, option_var_value):
option_var_string = ",".join(option_var_value)
cmds.optionVar(sv=(option_var_name, option_var_string))
def GetOptionVarStringArr(option_var_name):
option_var_string = cmds.optionVar(q=option_var_name)
option_var_value = option_var_string.split(",")
return option_var_value