MEL How-To #62

Back · Previous · Next Maya

How do I set defaults so Materials, Cameras, Layout views, et al. have my own settings every time I start a new scene?

The usual place to store user preferences is in the "userSetup.mel" script. However, this doesn't work for setting attributes of in-scene elements. The last thing Maya does before it gives you control - and this is after your "userSetup.mel" is executed - is to perform a ‘file -new’, clearing the scene. This annihilates any attributes you may try to set on Materials, Cameras and the like.

It is possible to create a scriptJob which triggers off of the ‘NewSceneOpened’ event. This will execute a script both after the "userSetup.mel" commands and after Maya performs its scene clear.

In your 'userSetup.mel' add the following line:

scriptJob -e NewSceneOpened defaultSceneUI;

Now create a "defaultSceneUI.mel" script that contains the settings you prefer:

global proc defaultSceneUI()
{
  // Set the colour of the initialShadingGroup to an Alias-like cyan
  setAttr lambert1.color 0.0 0.667 1.0;

  // Set all Cameras' Far Clipping Plane to 100.0
  string $cameras[] = `ls -type "camera"`;

  for ( $camera in $cameras )
  {
    setAttr ( $camera + ".farClipPlane" ) 100.0;
  }

  // Turn on the Polygon Statistics in Heads-up Display
  if ( `optionVar -q polyCount` == 0 )
    TogglePolygonCount;

}

Now every time you clear the scene the scriptJob will adjust the scene setup to your liking.

Note: this will not affect newly created items.. only the ones that exist in Maya's initial scene configuration.


Related How-To's

Wednesday, April 25, 2001