[MAYA-MEL] Accessing/Editing Maya Preferences

Lately a lot of my work has been creating tools that run batch actions on many, many, Maya files. The most recent requires making a fairly basic, comparatively, change to the preference settings in the scene.

I need to change Preferences -> Settings -> Working Units ->Time from film(24 FPS) to NTSC Field(60 FPS)

Now, I can change these settings in the userPrefs.mel by using

optionVar -sv “workingUnitsTime” “ntscf”;
optionVar -sv “workingUnitsTimeDefault” “ntscf”; // For Sure measure

However, this doesn’t then call the automatic update to the time slider that occurs when you change the setting through the menu.

It also appears that the menu makes calls to functions for these changes that aren’t in the command list, so I’m guessing they are hardcoded in C++:

prefWndUnitsChanged “time”;
setMinMaxPlayback …

To make things worse, even if I change the optionVars it doesn’t update the menu selection. So if the user has their save prefs on exit flag on, it overwrites anyway.

At this point, I’m considering using autohotkey to do it all through the menu, but it seems like there should be an easier way. What am I missing?

I assume you turned on “Echo All Commands” in the script editor to get those 2 commands displaying?

This is where the MEL command “whatIs” comes in real handy. Running this:
whatIs prefWndUnitsChanged

shows that it comes from a MEL file that lives in maya’s install directory. You can open it up and check out what its doing and how to use it.

Most (all?) of the MEL commands are found in maya’s installed scripts directory if they are not a “command” type.

So…why not try and use the same commands that maya uses when you change the settings in your preferences? or am i missing your point?

[QUOTE=bryceclark;10101]The most recent requires making a fairly basic, comparatively, change to the preference settings in the scene.

I need to change Preferences -> Settings -> Working Units ->Time from film(24 FPS) to NTSC Field(60 FPS)[/QUOTE]

if ( `currentUnit -q -time` != "ntscf" )	
	currentUnit -time ntscf;

However, this doesn’t then call the automatic update to the time slider that occurs when you change the setting through the menu.

the default behavior of currentUnit -updateAnimation is “true” so the example given above is fine “as is”.
If you didn’t want the keys adjusted in the timeslider…

if ( `currentUnit -q -time` != "ntscf" )	
	currentUnit -time ntscf -updateAnimation 0;

It also appears that the menu makes calls to functions for these changes that aren’t in the command list, so I’m guessing they are hardcoded in C++:
prefWndUnitsChanged “time”;
setMinMaxPlayback …

These are mel procedures in Maya’s scripts folder.
Even with the move to python solutions,
Maya is still built upon a mel architecture.
All these scripts are great reference sources:
the procedure…
prefWndUnitsChanged “time”;
assigns the optionVar value preference chosen in the drop down menu using the currentUnit command just
like in the above example.
The command is located within maya’s creatPrefsWndUI.mel file.
creatPrefsWndUI.mel is a collection of procedures that build the preferences window’s UI.
Use your text editor’s “find in file” function to find these mel scripts in your Maya/scripts directory.
( for instance: search setMinMaxPlayback to find the script and mel commands used to clean up the maya interface after the unit landscape has changed )

To make things worse, even if I change the optionVars it doesn’t update the menu selection. So if the user has their save prefs on exit flag on, it overwrites anyway.

If you use the currentUnit command the preference will be saved to the preference file. That will be reflected the “next” time the preference window is open.

I assume you are referring to an open preference window not updating with the new unit setting?
In which case…
is it reasonable to just check for an open window?

{ 
         
    global string $gPreferenceWindow; 
             
    if ( `currentUnit -q -time` != "ntscf" )     
        currentUnit -time ntscf -updateAnimation 1; 
         

    if ( `window -exists $gPreferenceWindow` ) 
        savePrefs; 
        deleteUI $gPreferenceWindow; 
}

And in this way, have your script save the preference?

:p: dbsmith beat me to it.

Maya scripts directory is the other mel manual.

[QUOTE=dbsmith;10105]I assume you turned on “Echo All Commands” in the script editor to get those 2 commands displaying?

This is where the MEL command “whatIs” comes in real handy. Running this:
whatIs prefWndUnitsChanged

shows that it comes from a MEL file that lives in maya’s install directory. You can open it up and check out what its doing and how to use it.

Most (all?) of the MEL commands are found in maya’s installed scripts directory if they are not a “command” type.

So…why not try and use the same commands that maya uses when you change the settings in your preferences? or am i missing your point?[/QUOTE]

That “whatIs” command is exactly what I needed. If something wasn’t in the command reference, I wasn’t really sure how else to track it down. I was about to try a “find in files” but this makes it a lot easier.

The reason I wasn’t using the same calls is because I didn’t know what arguments to pass it. I tried some trial and error, but it wasn’t getting me anywhere.

However, having the “whatIs” command at my disposal allows me to track down all the other info I need. Somehow I never found out about that command. Thanks!

[QUOTE=claydough;10107]

if ( `currentUnit -q -time` != "ntscf" )	
	currentUnit -time ntscf;

the default behavior of currentUnit -updateAnimation is “true” so the example given above is fine “as is”.
If you didn’t want the keys adjusted in the timeslider…

if ( `currentUnit -q -time` != "ntscf" )	
	currentUnit -time ntscf -updateAnimation 0;

These are mel procedures in Maya’s scripts folder.
Even with the move to python solutions,
Maya is still built upon a mel architecture.
All these scripts are great reference sources:
the procedure…
prefWndUnitsChanged “time”;
assigns the optionVar value preference chosen in the drop down menu using the currentUnit command just
like in the above example.
The command is located within maya’s creatPrefsWndUI.mel file.
creatPrefsWndUI.mel is a collection of procedures that build the preferences window’s UI.
Use your text editor’s “find in file” function to find these mel scripts in your Maya/scripts directory.
( for instance: search setMinMaxPlayback to find the script and mel commands used to clean up the maya interface after the unit landscape has changed )

If you use the currentUnit command the preference will be saved to the preference file. That will be reflected the “next” time the preference window is open.

I assume you are referring to an open preference window not updating with the new unit setting?
In which case…
is it reasonable to just check for an open window?

{ 
         
    global string $gPreferenceWindow; 
             
    if ( `currentUnit -q -time` != "ntscf" )     
        currentUnit -time ntscf -updateAnimation 1; 
         

    if ( `window -exists $gPreferenceWindow` ) 
        savePrefs; 
        deleteUI $gPreferenceWindow; 
}

And in this way, have your script save the preference?[/QUOTE]

This was incredibly helpful. Thanks for the extensive breakdown of the solution. Somehow I missed “currentUnit” in the reference!