【问题标题】:Select all joints of a character with Maya MEL使用 Maya MEL 选择角色的所有关节
【发布时间】:2017-09-11 13:19:14
【问题描述】:

我在 Maya 中编写了一个 MEL 脚本。所以我想选择一个关节,然后运行 ​​MEL 脚本,它会选择该关节及其所有子节点。我对 MEL 很陌生,所以在运行代码时,它会引发一堆错误。您能帮我减少错误或更好地消除所有错误吗?

脚本:

string $joints[];
string $current[] = 'ls -selection';

proc selectJoints (){
    if ('searchJoints($joints)' == 0){
       $joints['size($joints)'] = $current[0];
       pickWalk -d down; 
       $current[0] = 'ls -sl';
       selectJoints();
    }
    else{
        pickWalk -d right;
        $current[0] = 'ls -sl';
        if('searchJoints($joints)' == 0){
            selectJoints();
        }
        else{
            pickWalk -d up;
            $current[0] = 'ls -sl';
            if($current[0] == $joints[0]){
                selectJoints();
            }
        }
    }
    return;
}

select ($Joints);

proc int searchJoints (string $jns[]){
    int $result = 0;
    for ($joint in $jns[]){
        if ($current[0] == $joint){
            return 1;
        }
    }
    return 0;
}

【问题讨论】:

    标签: maya mel


    【解决方案1】:

    所以,我知道您的问题是关于 MEL 的,很抱歉无法为您提供帮助,但我认为我可以在 python 和 pymel 方面为您提供帮助。

    在脚本编辑器的 Python 选项卡中尝试此代码:

    import pymel.core as pm
    
    # get selected joint
    selectedJoint = pm.selected()[0]
    
    #get all children from the selected joint and puts it in a list
    joints = selectedJoint.listRelatives(allDescendents = True)
    
    #adds first selected joint to same list
    joints.append(selectedJoint)
    
    #clears selection
    pm.select(clear = True)
    
    #loop thru list of joints
    for item in joints:
        #toggle selection on selected joint and all its descendents
        pm.select(item, tgl = True)  
    

    我不知道为什么要使用 MEL,我是直接用 pymel 开始的,它似乎更强大。你能告诉我为什么 MEL 吗?...我想我可能会错过一些东西。无论如何,我认为这个短代码可以解决问题。祝你好运!请注意,那里没有故障保险柜。因此,请确保在运行脚本之前选择要运行的一个关节。

    【讨论】:

      【解决方案2】:

      你可以这样做:

      select -hi;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-04
        • 1970-01-01
        • 2014-04-25
        • 1970-01-01
        • 2017-04-21
        相关资源
        最近更新 更多