用mel编写自定义节点的属性编辑器界面

用mel编写自定义节点的属性编辑器界面比较麻烦,而且网上例子又少,下面给出一个范例,说明基本的格式
  1. // 初始化节点时调用
  2. global proc initControl(string $attrName)
  3. {
  4. // 传进来的参数是节点属性名,使用这个方法获得节点名称
  5. string $nodeName = `plugNode $attrName`;
  6. setUITemplate -pst "attributeEditorTemplate";
  7. button -label "Compute Weight" -c ("cageDeform -init -name " + $nodeName) computeWeightButton;
  8. setUITemplate -ppt;
  9. }
  10. // 修改节点时(例如点击另一个同类节点)调用
  11. // 此函数的目的是对按钮绑定的命令做相应修改,使其能应用于相应节点
  12. global proc modifyControl(string $attrName)
  13. {
  14.   // 当attrName = “cageDeformer1.noAttr”
  15. // plugNode 命令能够提取节点名字cageDeformer1
  16. string $nodeName = `plugNode $attrName`;
  17. print $nodeName;
  18. button -e -c ("meshControl -init -name " + $nodeName) computeWeightButton;
  19. }
  20. // 函数名同文件名一样,同节点名cageDeformer对应
  21. global proc AEcageDeformerTemplate(string $nodeName)
  22. {
  23. editorTemplate -beginScrollLayout;
  24.         // 新建一个卷展栏
  25. editorTemplate -beginLayout "Weight Scheme" -collapse false;
  26. // addControl自动指定合适类型的控件
  27. editorTemplate -addControl "maxNeighbourNum";
  28. editorTemplate -addControl "weightPower";
  29.          // 在指定的时机调用前面的函数
  30. editorTemplate -callCustom "initControl" "modifyControl" "noAttr";
  31. editorTemplate -endLayout;
  32. editorTemplate -suppress "outMesh";
  33. editorTemplate -suppress "inControlMesh";
  34. editorTemplate -suppress "refMesh";
  35. editorTemplate -suppress "refControlMesh";
  36. editorTemplate -beginLayout "Node Behavior" -collapse true;
  37. editorTemplate -addControl "nodeState";
  38. editorTemplate -addControl "caching";
  39. editorTemplate -endLayout;
  40. editorTemplate -addExtraControls;
  41. editorTemplate -endScrollLayout;
  42. }

下面是-callCustom的文档解释

Specifies that at this point in the template when building the dialog, the procedure specified by the first argument is to be called to create some UI objects when a new node type is edited. The procedure specified by the second argument is to be called if an attribute editor already exists and another node of the same type is now to be edited. The replacing procedure should connect any controls created by the creating procedure to the equivalent attributes in the new node. A list of zero or more attributes specifies the attributes which the two procedures will involve. The procedures should have the signature:
proc AEcustomNew(string attributeName1, string attributeName2)
The number of attributes specified in the call should correspond to the number of attributes in the procedure signature.
 




posted @ 2015-02-11 18:03  dydx  阅读(312)  评论(0编辑  收藏  举报