LoginSignup
1
0

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
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0