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

Synopsis

optionVar([arraySize=string], [clearArray=string], [exists=string], [floatValue=[string, float]], [floatValueAppend=[string, float]], [intValue=[string, int]], [intValueAppend=[string, int]], [list=boolean], [remove=string], [removeFromArray=[string, int]], [stringValue=[string, string]], [stringValueAppend=[string, 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, clearArray, exists, floatValue, floatValueAppend, intValue, intValueAppend, list, remove, removeFromArray, stringValue, stringValueAppend, version
Long name (short name) Argument types Properties
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).
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.
floatValue(fv) [string, float] createmultiuse
creates a new variable named "string" with double 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)
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.
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.
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.
version(v) int create
Preferences version number to warn about incompatbile preference files
clearArray(ca) string createmultiuse
If there is an array named "string", it is set to be empty. Empty arrays are not saved.
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.
exists(ex) string create
returns 1 if a variable named "string" exists, 0 otherwise. All other flags will be ignored if this is used. (Query has higher precedence)
list(l) boolean create
this returns a list of all the defined variable names. All other flags will be ignored if this one is used. (Query and exists flags have a higher precedence).

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 #