Maya Python:如何对这些 FK 控件进行分层父级设置?

Maya Python: How do I parent these FK controls hierarchically?

提问人:Dasteel 提问时间:11/16/2023 更新时间:11/16/2023 访问量:43

问:

我一直在尝试根据我在这个论坛上找到的内容来运行此代码: https://discourse.techart.online/t/maya-python-fk-controls-generator-parenting-issue/5395

我注释掉的第一个列表有点工作,但它可以工作的次数有限。我想做的是让这个脚本不仅创建 fk 控件(它做得很好),我希望它也根据选定的顺序将控件彼此父级。

要运行它很简单,只需创建一个关节链,选择您想要的任何关节,将脚本粘贴到一个空的 python 选项卡中,然后按 Enter。它将创建控件,但不会正确地为它们设置父级。我把脚本放在下面,供任何想要尝试的人使用:

import maya.cmds as cmds

#create variable for the selected joints
selected = cmds.ls(sl=True)

#clears the selection
cmds.select(cl=True)

#create empty list for the new controls
CL = []




#parent = None
#for the joints in selection, run the following code
for s in selected:

    #create variable for the position/rotation of the joints
    pos = cmds.xform(s, q=True, t=True, ws=True)
    rot = cmds.xform(s, q=True, rotation=True, ws=True)

    #create 3lvl controls and position them on top of joints
    ctrl = cmds.circle(n=str(s + '_ctrl'), radius=0.6,nr=(1,0,0), ch=False) 
    cmds.group(n=str(s + '_sdk'))
    offset = cmds.group(n=str(s + '_offset'))

    #snap the controls to the position of the joint
    cmds.xform(offset, translation=pos, ws=True)
    cmds.xform(offset, rotation=rot, ws=True)

    #parent constraint joints to ctrls
    cmds.parentConstraint(ctrl, s)

    #append offset nodes to CL
    CL.append(offset)
    
    #offsets = [selected[0]+ '_ctrl_offset',selected[1]+ '_ctrl_offset',selected[2]+ '_ctrl_offset',selected[3]+ '_ctrl_offset',selected[4]+ '_ctrl_offset']
    #controls = [selected[0]+ '_ctrl',selected[1]+ '_ctrl',selected[2]+ '_ctrl',selected[3]+ '_ctrl',selected[4]+ '_ctrl']
    
#I know a zip loop works, I just dont how to write it properly to get it to parent hierarchically with these variable lists
    offsets = [str(s + '_offset')]
    controls = [str(s + '_ctrl')]
    
    
    
    for offset, control in zip(offsets, controls[-1:]):
      cmds.parent(control, offset)
Python 控件 Maya Nurbs

评论


答: 暂无答案