OptionVar are option variables that are stored locally to a computer and carry over between sessions of maya. They are stored per maya version so if you have some in 2011 and you open 2012, they won’t be there unless created in that maya version.

We use them for storing gui settings between maya sessions and as local buffers.

This class is to make optionVar’s in maya behave a little more like other instanced nodes or transforms.

Superclass : None

Subclass:  None


  • varName – (required) – name of an existing option var or a new name to be created. We tag all of our cgm option vars with cgmVar_whatever to make them easy to find in the list of maya optionVars.
  • varType – ‘string’,’int’, ‘float’ are expected answers. The class will infer type from a value flag if provided.
  • value – (string,float,int,list) – the information to be stored at call
  • defaultValue  (string,float,int,list) – information to only be stored if the object is created on call. We find this useful for declaring with gui’s in particular as resetting a gui is then just a matter of deleting it’s optionVars and reloading it


  • value – (getValue,setValue,purge)
    • getValue – instance.value returns value
    • setValue – instance.value = string or 1 or 2.0 or [item1,item2] to set a value
    • purge – del instance.value deletes the optionVar
  • varType (getType,SetType)
    • getType – returns optionVar type
    • setType(varType) – change optionVar type


  • clear() – clear an optionVar of data
  • append(value) – append a value
  • remove(value)  – removes a value
  • extend(valuesList) – extends a value list
  • toggle() – must be an int, if so, toggles value. Useful for check box connection
  • select() – select the items of a list if they exist
  • existCheck() – prunes non existing objects from the list. Useful for using an optionVar as a buffer


from cgm.core import cgmMeta as cgmM
if mc.optionVar(exists = 'cgmVar_intTest'):#If the optionVar already exists
    mc.optionVar(remove = 'cgmVar_intTest')#delete it

OptionVarInstance = cgmM.cgmOptionVar('cgmVar_intTest')#No arg should default to int

assert OptionVarInstance.varType == 'int'
assert OptionVarInstance.value == 0,"Value should be 0"

OptionVarInstance.value = 3
assert OptionVarInstance.value == 3,"Value should be 3"

OptionVarInstance.varType = 'float'
assert OptionVarInstance.value == 3.0,"Value should be 3.0"
assert OptionVarInstance.varType == 'float',"Form should be float after conversion"

OptionVarInstance.varType = 'string'
assert OptionVarInstance.value == '3.0',"Value should be 3.0"
assert OptionVarInstance.varType == 'string',"Form should be string after conversion"

OptionVarInstance.value = ['cat','rat','dog']
assert type(OptionVarInstance.value) is list, "Value should be list"
assert OptionVarInstance.value == ['cat','rat','dog']

del OptionVarInstance.value
assert not mc.optionVar(exists = 'cgmVar_intTest'), "optionVar should be gone"