MEL How-To #50

Back · Previous · Next Maya

How do I control the Grid display settings via MEL?

The MEL command to do this is, predictably:


Be careful when analyzing the flags for this command. The '-size' flag, which you may expect to control the Grid Spacing, is actually equivalent to the "Extent" setting in the Options panel. Also be aware that "Extent" effects only non-orthographic views.

After setting the grid display settings with the MEL command the values in the Grid Options panel do not update with the new values, even if you close and re-open the panel. This is because the values in the options panel are derived from optionVars and not from the actual grid settings (tsk tsk A|w!).

Due to the way the ‘performGridOptions.mel’ script is designed (oh my gawd, what a contrived mess it is!) there is no easy-to-call function to get things in sync. You must set the appropriate optionVar after applying your own grid settings and then call the gridSetup() function with an (somewhat) arbitrary UI control name. Since the gridSetup() does no error-checking to assert the existence of the UI controls it is modifying (by its design, this is somewhat forgivable), you should provide this assertion yourself:

Grid Spacing (a.k.a. Grid)

float $gridSpacing = 30.48;
grid -spacing $gridSpacing;
optionVar -fv gridSpacing $gridSpacing;
if ( `floatFieldGrp -q -exists gridSpacingField` )
      gridSetup( "OptionBoxWindow", 0 );

Grid Divisions (a.k.a. Subdivisions)

float $gridDivisions = 2;
grid -size $gridDivisions;
optionVar -fv gridDivisions $gridDivisions;
if ( `intSliderGrp -q -exists gridDivisionsField` )
  gridSetup( "OptionBoxWindow", 0 );

Grid Size (a.k.a. Extent)

float $gridSize = 16;
grid -size $gridSize;
optionVar -fv gridSize $gridSize;
if ( `floatFieldGrp -q -exists gridSizeField` )
  gridSetup( "OptionBoxWindow", 0 );

Grid Style

int $gridStyle = 2;  // "Grid" style
grid -style $gridStyle;
optionVar -fv gridStyle $gridStyle;
if ( `radioButtonGrp -q -exists gridStyleButtonGrp` )
  gridSetup( "OptionBoxWindow", 0 );

Tuesday, December 05, 2000