Mel Script - Using optionVar

 

 

 

Often when writing mel scripts, we may have a number of settings for our tools and commands. One example would be creating a polygon cube. The default settings for this are stored so that if you close Maya, the next time you open Maya and create a cube; it will use the previous settings.

optionVar is basically a little mel command that allows us to store some tool settings for the next time Maya opens. First off though, if you execute the command

optionVar -list;

Maya will list all current user options it is storing.

 

 

 

 

Example 1 : Creating an option

optionVar allows us to easily create some basic user settings. This is just a simple example....

 

 

	
	{	
		// if the option doesn't exist, create it
		if( !`optionVar -exists "myName"` )
		{
			// add a string option called "myName" and its
			// value to "Rob"
			optionVar -stringValue "myName" "Rob";
		}

		// use the -query flag to retrieve the option value
		print( `optionVar -query "myName"` + "\n" );

		// remove the option
		optionVar -remove "myName";
	}