Sat, Oct 13th, 2012
posted by jjburton 01:10 PM

So saw some questions on these enigmas around and wanted to attempt to shed some light on them.

optionVars are maya devices for saving information between maya sessions, from say one tool session to another or any other wide variety of things. By default you use them like something like this:

If you decided you wanted to play with optionVars. They’re awesome but can be a bugger to get working the way you want them. We use them to save settings between gui sessions and even to send info to some stand alone functions.

If you want to add to a string one you have to remember it’s a string one and use a different flag than a int or float one. It got confusing to us, so we decided to go a different route.

We wrote a class wrapper for dealing with them that made it easier for us to get a handle on so that we call them at the top of any gui with something like:

That initializes the option var to an instance that can be appended, rebuilt, culled purged, cleared, call, converted or whatever in any of our tools.

The defaultValue flag sets the value only if the optionVar doesn’t exist. We did that so that if a specific tool is reset and has it’s flags wiped. It builds again with the default ‘factory’ settings. It also converts on the fly so if you pass a string to a non string optionVar, it converts it to a string, and so on.

Settings are called and set via commands like:

We also flag all of our optionVar’s with a ‘cgmVar’ so that we can easily do a full wipe of our variables when needed for testing.

You’re welcome to give it a try if you like or take part of it it works for you and run with it or join us and help make it better. It’s in the cgmTool box from cgMonks – cgm/lib/classes/OptionVarFactory

Have a great weekend!

 
Creative Commons License

Categories