Go to: Synopsis. Return value. Flags. Python examples.

Synopsis

optionVar([arraySize=string], [category=string], [clearArray=string], [clearStash=string], [default=boolean], [exists=string], [floatArray=string], [floatValue=[string, float]], [floatValue2=[string, float, float]], [floatValue3=[string, float, float, float]], [floatValue4=[string, float, float, float, float]], [floatValueAppend=[string, float]], [init=boolean], [intArray=string], [intValue=[string, int]], [intValue2=[string, int, int]], [intValue3=[string, int, int, int]], [intValue4=[string, int, int, int, int]], [intValueAppend=[string, int]], [list=boolean], [listCategories=boolean], [listModified=boolean], [prefFile=string], [remove=string], [removeFromArray=[string, int]], [stash=string], [stringArray=string], [stringValue=[string, string]], [stringValueAppend=[string, string]], [transient=boolean], [unstash=string], [version=int])

Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.

optionVar is undoable, queryable, and NOT editable.

This command allows you to set and query variables which are persistent between different invocations of Maya. These variables are stored as part of the preferences.

Return value

int0 or 1 for the exists option
string[]When the list option is used

In query mode, return type is based on queried flag.

Flags

arraySize, category, clearArray, clearStash, default, exists, floatArray, floatValue, floatValue2, floatValue3, floatValue4, floatValueAppend, init, intArray, intValue, intValue2, intValue3, intValue4, intValueAppend, list, listCategories, listModified, prefFile, remove, removeFromArray, stash, stringArray, stringValue, stringValueAppend, transient, unstash, version
Long name (short name) Argument types Properties
arraySize(arraySize) string create
returns the size of the array named "string". If no such variable exists, it returns 0. If the variable is not an array, it returns 1.
category(cat)
2023
string create
Set category for the specified variables. This flag can also be combined with list/listModified flags to get all the variables in the specified category.
clearArray(ca) string createmultiuse
If there is an array named "string", it is set to be empty. Empty arrays are not saved.
clearStash(cs) string createmultiuse
Clear backup copy of a variable.
default(d)
2023
boolean create
The variable's current and default values will be set to the specified values. This flag can also be combined with the query flag to get the default value or with the exists flag to determine if a default value has been specified. It can also be used with list/listModifed flags to list variables with a default value.
exists(ex) string create
Returns 1 if a variable named "string" exists, 0 otherwise. The default/transient flags can be used to list variables that have a default value or are transient. All other flags will be ignored if this is used. (Query has higher precedence)
floatArray(fa) string createmultiuse
Creates a new empty float array variable named "string". If a variable already exists with this name, it is overridden in favour of the new value (even if the type is different).
floatValue(fv) [string, float] createmultiuse
creates a new variable named "string" with float value "float". If a variable already exists with this name, it is overridden in favour of the new value (even if the type is different)
floatValue2(fv2)
2023
[string, float, float] createmultiuse
Creates a new variable named "string" with a 2 element float array. If a variable already exists with this name, it is overridden in favour of the new value (even if the type is different).
floatValue3(fv3)
2023
[string, float, float, float] createmultiuse
Creates a new variable named "string" with a 3 element float array. If a variable already exists with this name, it is overridden in favour of the new value (even if the type is different).
floatValue4(fv4)
2023
[string, float, float, float, float] createmultiuse
Creates a new variable named "string" with a 4 element float array. If a variable already exists with this name, it is overridden in favour of the new value (even if the type is different).
floatValueAppend(fva) [string, float] createmultiuse
adds this value to the end of the array of floats named "string". If no such array exists, one is created. If there was a float value with this name before, it becomes the first element of the array. If any other kind of value existed, it is overridden.
init(ini)
2023
boolean create
Used to initialize or reset variables. If the flag is set to true or the variable does not exist then the variable's current and default values will be set to the specified values. If the flag if set to false then only the default value will be set and the current value will not be modified.
intArray(ia) string createmultiuse
Creates a new empty int array variable named "string". If a variable already exists with this name, it is overridden in favour of the new value (even if the type is different).
intValue(iv) [string, int] createmultiuse
creates a new variable named "string" with integer value "int". If a variable already exists with this name, it is overridden in favour of the new value (even if the type is different).
intValue2(iv2)
2023
[string, int, int] createmultiuse
Creates a new variable named "string" with a 2 element int array. If a variable already exists with this name, it is overridden in favour of the new value (even if the type is different).
intValue3(iv3)
2023
[string, int, int, int] createmultiuse
Creates a new variable named "string" with a 3 element int array. If a variable already exists with this name, it is overridden in favour of the new value (even if the type is different).
intValue4(iv4)
2023
[string, int, int, int, int] createmultiuse
Creates a new variable named "string" with a 4 element int array. If a variable already exists with this name, it is overridden in favour of the new value (even if the type is different).
intValueAppend(iva) [string, int] createmultiuse
adds this value to the end of the array of ints named "string". If no such array exists, one is created. If there was an int value with this name before, it becomes the first element of the array. If any other kind of value existed, it is overridden.
list(l) boolean create
This returns a list of all the defined variable names. The category flag can be used to list variables in the specified category and the default/transient flags can be used to list variables that have a default value or are transient. All other flags will be ignored if this one is used. (Query and exists flags have a higher precedence).
listCategories(lc)
2023
boolean create
This returns a list of all the defined variable categories. All other flags will be ignored if this one is used. (Query and exists flags have a higher precedence).
listModified(lm)
2023
boolean create
This returns a list of all the variables that have been changed from their default value. Variables that don't have a default value will also be returned unless the default flag is used to filter the list to variables that have a default value. The category flag can also be used to filter the list by category. All other flags will be ignored if this one is used. (Query and exists flags have a higher precedence).
prefFile(pf)
2023
string createquery
Flag need to be used in conjunction with category Specify where the optionVars from specified category need to be saved when saving preferences.
remove(rm) string createmultiuse
removes the variable named "string", if one exists.
Note: all removals are done before any value setting, if both the -r and other (-sv, -iv, -fv) flags are used in the same command.
removeFromArray(rfa) [string, int] createmultiuse
removes the element numbered "int" in the array named "string". Everything beyond it then gets shuffled down.
stash(st) string createmultiuse
Make a backup copy of a variable.
stringArray(sa) string createmultiuse
Creates a new empty string array variable named "string". If a variable already exists with this name, it is overridden in favour of the new value (even if the type is different).
stringValue(sv) [string, string] createmultiuse
creates a new variable named using the first string with value given by the second string. If a variable already exists with this name, it is overridden in favour of the new value (even if the type is different)
stringValueAppend(sva) [string, string] createmultiuse
adds the value given by the second string to the end of the array of strings named by the first string. If no such array exists, one is created. If there was a string value with this name before, it becomes the first element of the array. If any other kind of value existed, it is overridden.
transient(t)
2023
boolean create
Indicates that specified variables will not be persisted across sessions. This flag can also be combined with -exists to determine if a variable is transient.
unstash(us) string createmultiuse
Restore a variable from a backup copy.
version(v) int create
Preferences version number to warn about incompatbile preference files

Flag can appear in Create mode of command Flag can appear in Edit mode of command
Flag can appear in Query mode of command Flag can have multiple arguments, passed either as a tuple or a list.

Python examples

import maya.cmds as cmds

cmds.optionVar( iv=('defaultTriangles', 4), sv=('defaultFileName', 'buffalo.maya') )
cmds.optionVar( exists='defaultTriangles' )
# Result: 1 #
cmds.optionVar( q='defaultFileName' )
# Result: buffalo.maya #
cmds.optionVar( list=True )
cmds.optionVar( remove='defaultTriangles' )
cmds.optionVar( exists='defaultTriangles' )
# Result: 0 #