一半君的总结纸

听话只听一半君

#106 How do I find the type of an anonymous MEL UI control?

The “objectTypeUI” command may be used to query the type of a MEL UI control.

objectTypeUI AEnodeNameHeaderLayout;
// Result: formLayout //

objectTypeUI directKeyTool;
// Result: toolButton //

objectTypeUI bdeOutOfRangeColor;
// Result: canvas //

Watch out, tho’. It can throw you a change-up when querying items from Maya’s custom control groups – e.g. a “radioButtonGrp” or “attrFieldSliderGrp.”

string $ca[] = `layout -q -ca columnLayout12`;

// Result: polyObjsAffectedRadio separator5 polyVerticesDisplayCheck
           separator6 polyEdgeDisplayRadio borderEdgeHiliteDisplayCheck
           borderEdgeSizeSlider separator7 polyFacetDisplayCheck
           separator8 polyItemDisplayCheck normalSizeSlider
           polyUVDisplayCheck separator9 colorShadedDisplayCheck
           colorMaterialPopup materialBlendPopup separator10
           backfaceCullPopup //

for ( $c in $ca )
{
  print ( $c + ": " + (`objectTypeUI $c`) + "\n" );
}

Result (formatted for easy reading):

       polyObjsAffectedRadio: rowGroupLayout
                  separator5: separator
    polyVerticesDisplayCheck: rowGroupLayout
                  separator6: separator
        polyEdgeDisplayRadio: rowGroupLayout
borderEdgeHiliteDisplayCheck: rowGroupLayout
        borderEdgeSizeSlider: rowGroupLayout
                  separator7: separator
       polyFacetDisplayCheck: rowGroupLayout
                  separator8: separator
        polyItemDisplayCheck: rowGroupLayout
            normalSizeSlider: rowGroupLayout
          polyUVDisplayCheck: rowGroupLayout
                  separator9: separator
     colorShadedDisplayCheck: rowGroupLayout
          colorMaterialPopup: rowGroupLayout
          materialBlendPopup: rowGroupLayout
                 separator10: separator
           backfaceCullPopup: rowGroupLayout

Now extend the query into a… rowGroupLayout? Wazzat? Well, it’s a pretty good clue that this is a layout of some sort; perhaps we can generalize and again use the “layout” command.

string $ca[] = `layout -q -ca polyVerticesDisplayCheck`;
// Result: label check1 check2 check3 //

(Incidentally, querying via “rowLayout” works here, too.)

string $ca[] = `rowLayout -q -ca polyVerticesDisplayCheck`;
// Result: label check1 check2 check3 //

for ( $c in $ca )
{
  print ( $c + ": " + (`objectTypeUI $c`) + "\n" );
};

Results:

 label: staticText
check1: checkBox
check2: checkBox
check3: checkBox

And now what? The “checkBox” controls are all well and good, but “staticText?” It’s clear you’ll have to back up a step and be able to recognize this type of layout is actually a checkBoxGrp:

checkBoxGrp -q -label polyVerticesDisplayCheck;
// Result: Vertices //

checkBoxGrp -q -value1 polyVerticesDisplayCheck;
// Result: 1 //

checkBoxGrp -q -value2 polyVerticesDisplayCheck;
// Result: 1 //

checkBoxGrp -q -value3 polyVerticesDisplayCheck;
// Result: 1 //

checkBoxGrp -q -value4 polyVerticesDisplayCheck;
// Error: line 1: Object not found: check4 //

Oops.. you’ll also have to take care to consult the number of children before you query willy-nilly (since you cannot query the ‘-numberOfCheckBoxes’ flag).

Or how about this one from the Attribute Editor:

string $ca[] = `layout -q -ca columnLayout3`;

// Result: attrFieldSliderGrp1 formLayout52 attrFieldSliderGrp2
           formLayout53 attrFieldSliderGrp3 formLayout54
           attrFieldSliderGrp4 formLayout55 attrFieldSliderGrp5
           formLayout56 attrFieldSliderGrp6 //

for ( $c in $ca )
{
  print ( $c + ": " + (`objectTypeUI $c`) + "\n" );
};

Results:

attrFieldSliderGrp1: rowGroupLayout
       formLayout52: formLayout
attrFieldSliderGrp2: rowGroupLayout
       formLayout53: formLayout
attrFieldSliderGrp3: rowGroupLayout
       formLayout54: formLayout
attrFieldSliderGrp4: rowGroupLayout
       formLayout55: formLayout
attrFieldSliderGrp5: rowGroupLayout
       formLayout56: formLayout
attrFieldSliderGrp6: rowGroupLayout

string $ca[] = `layout -q -ca attrFieldSliderGrp1`;

// Result: AFGlabel AFGfield //

for ( $c in $ca )
{
  print ( $c + ": " + (`objectTypeUI $c`) + "\n" );
};

AFGlabel: exprStaticText
AFGfield: exprFloatField

Hmmm.. that doesn’t help. Again, back up and recognize “AFGlabel” and “AFGfield” as controls within an attrFieldSliderGrp:

attrFieldSliderGrp -q -label attrFieldSliderGrp1;
// Result: Max Triangles //

attrFieldSliderGrp -q -at attrFieldSliderGrp1;
// Result: pCubeShape1.maxTriangles //

In other words, in order to query the properties of Maya’s built-in control groups, you’ll need to devise some sort of logic to be able to recognize a layout’s type by its children. Remember, you can always assert whether a control (or layout) is, or isn’t, a presumed type by using an ‘-exists’ query:

radioButtonGrp -q -exists polyVerticesDisplayCheck;
// Result: 0 //

rowLayout -q -exists polyVerticesDisplayCheck;
// Result: 1 //

checkBoxGrp -q -exists polyVerticesDisplayCheck;
// Result: 1 //

Related How-To’s

19 Feb 2005

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: