查询着色节点Maya Python

时间:2015-02-26 09:43:51

标签: python maya

我目前遇到问题,我想查询输入X' maya中的multiplyDivide节点,并将查询后的数字放入" inputX'另一个multiplyDivide节点。

该脚本当前为手臂设置了弹性IK。使用肩膀和手腕之间的距离(在某个点,这是我想要查询的),然后骨骼将伸展。显然,我不想将两者连接在一起。

def stretchyIK(firstJointStore, lastJointStore, side, limb):

    GlobalMoveRig = cmds.rename ('GlobalMove_Grp_01')
    locFirstJoint = cmds.spaceLocator (n='Loc_' + firstJointStore + '_0#')
    locLastJoint = cmds.spaceLocator (n='Loc_' + lastJointStore + '_0#')
    pointLoc1 = cmds.pointConstraint (side + '_Fk_' + firstJointStore + suffix, locFirstJoint)
    pointLoc2 = cmds.pointConstraint (side + '_Fk_' + lastJointStore  + suffix, locLastJoint)
    cmds.delete (pointLoc1, pointLoc2)
    cmds.pointConstraint (side + '_FK_' + firstJointStore + suffix, locFirstJoint)
    cmds.pointConstraint (ikCtr, locLastJoint)
    cmds.parent (locFirstJoint, locLastJoint, 'Do_Not_Touch')
    #Creating Nodes for Stretchy IK
    IkStretch_DisNode = cmds.shadingNode ('distanceBetween', asUtility=True, n='DistBet_IkStretch_' + side + limb + '_#')
    cmds.connectAttr (locFirstJoint[0] + '.translate', IkStretch_DisNode + '.point1')
    cmds.connectAttr (locLastJoint[0] + '.translate', IkStretch_DisNode + '.point2')
    IkStretch_DivNode = cmds.shadingNode ('multiplyDivide', asUtility=True, n='Div_IkStretch_' + side + limb + '_#')
    cmds.setAttr (IkStretch_DivNode + '.operation', 2)
    input = cmds.connectAttr (IkStretch_DisNode + '.distance', IkStretch_DivNode + '.input1.input1X')   ########HELP NEEDED HERE
    cmds.setAttr (ikCtr + '.translateX', 2)
    IkStretch_MultNode = cmds.shadingNode ('multiplyDivide', asUtility=True, n='Mult_IkStretch_' + side + limb + '_#')
    cmds.setAttr (IkStretch_MultNode + '.input1X', IkStretch_DivNode + '.input1.input1X')#WAIT FOR PAUL
    cmds.connectAttr (GlobalMoveRig + '.scaleY', IkStretch_MultNode + '.input2X')
    cmds.connectAttr (IkStretch_MultNode + '.outputX', IkStretch_DivNode + '.input2X')
    IkStretch_Cond_Equ = cmds.shadingNode ('condition',  asUtility=True, n='Cond_Equ_IkStretch_' + side + limb + '_#')
    IkStretch_Cond_GrtEqu = cmds.shadingNode ('condition',  asUtility=True, n='Cond_GrtEqu_IkStretch_' + side + limb + '_#')
    cmds.setAttr (IkStretch_Cond_GrtEqu + '.operation', 3)
    cmds.connectAttr (ikCtr + '.Enable', IkStretch_Cond_Equ + '.firstTerm')
    cmds.setAttr (IkStretch_Cond_Equ + '.secondTerm', 1)
    cmds.connectAttr (IkStretch_DisNode + '.distance', IkStretch_Cond_GrtEqu + '.firstTerm')
    cmds.connectAttr (IkStretch_MultNode + '.outputX', IkStretch_Cond_GrtEqu + '.secondTerm')
    cmds.connectAttr (IkStretch_DivNode + '.outputX', IkStretch_Cond_GrtEqu + '.colorIfTrueR')
    cmds.connectAttr (IkStretch_Cond_GrtEqu + '.outColorR', IkStretch_Cond_Equ + '.colorIfTrueR')
    cmds.connectAttr (IkStretch_Cond_GrtEqu + '.outColorR', side + '_Ik_' + secondJointStore + suffix + '.scaleX')
    cmds.connectAttr (IkStretch_Cond_GrtEqu + '.outColorR', side + '_Ik_' + firstJointStore + suffix + '.scaleX')

2 个答案:

答案 0 :(得分:1)

是的,您的错误非常有意义......您正在寻找的属性实际上只是'.input1X'而不是'.input1.input1X'

我知道,这不是很清楚,但你将来会知道。顺便说一下,找出这样的东西的简单方法是手动连接Maya中的东西并在脚本编辑器中查看MEL输出。你每次都会得到真正的交易,然后将这些内容翻译成Python很快。

<强>因此

cmds.connectAttr(IkStretch_DisNode + '.distance', IkStretch_DivNode + '.input1X') 

顺便说一下,我不确定你为什么要把结果分配给input。我承认我不确定会返回什么,但我不知道它会如何有用!

另外:要回答您的直接问题,您可以使用getattr来查询该值。

cmds.setAttr(
    IkStretch_MultNode + '.input1X', 
    cmds.getattr(IkStretch_DivNode + '.input1X')
)

答案 1 :(得分:0)

在我的情况下,未正确评估被指定为新属性值的变量。 setAttr将变量值解释为文本,即使该值是作为浮点值输入的。

因此,我只是分配了变量并将其设置为在命令中浮动变量。就我而言,我做了以下事情:

cmds.setAttr(Node + '.input1X', float(variable))