一半君的总结纸

听话只听一半君

#106 如何找到一个不知道名字的(Anonymous)MEL UI control的类型(type)?

可以用 “objectTypeUI” 命令来查询MEL UI control的类型(type).

objectTypeUI AEnodeNameHeaderLayout;
// Result: formLayout //

objectTypeUI directKeyTool;
// Result: toolButton //

objectTypeUI bdeOutOfRangeColor;
// Result: canvas //

但需要注意的是,他可能会返回下面的“不正确的”结果,比如当里用他查询 Maya的 custom control groups 的时候,比如 “radioButtonGrp” 或者 “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" );
}

结果如下 (重新排版了以便于比较):

       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

你会发现上面的结果里有没见过的 rowGroupLayout? 这至少暗示了这是某种 layout; 也许我们可以试着用通用的 “layout” 命令来查询试试.

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

(这里恰巧用 “rowLayout” 命令查询也刚好可以.)

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

然后现在怎么办? “checkBox” controls 显然我们是见过的, 但是 “staticText?” 是什么,此时显然你应该退回上一步,你应该可以猜出这个 layout 其实是一个 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.. 上面出错了,你在像上面这样用的时候最好先查询他有几个children, (因为你没法简单的查询( query) ‘-numberOfCheckBoxes’ flag).

再看看下面这个 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.. 从上面的结果看不出什么. 同样应该后退一步,猜到 “AFGlabel” 和 “AFGfield” 其实是 attrFieldSliderGrp里的controls:

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

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

综上所述,当你query Maya内建 ( built-in)的 control groups的属性(  properties)的时候, 你应该自己摸索出几条规律,当你一看到类似名字的时候,就应该猜到需要找的control是哪一种(通过他的children的特殊的命名). 猜错没关系,你总是可以用如下命令来验证你猜的control (或者layout)的type对不对,只要用上 ‘-exists’ flag来验证就行了:

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 博主赞过: