简体   繁体   English

查询着色节点Maya Python

[英]Querying a shading node Maya Python

I am currently having a problem where i want to query the 'inputX' of a multiplyDivide Node in maya and put the queried number into the 'inputX' of another multiplyDivide node. 我目前遇到一个问题,我想查询玛雅人中的multipliDivide节点的“ inputX”,并将查询到的数字放到另一个multiplyDivide节点的“ inputX”中。

The script currently makes an stretchy IK set up for an arm. 该脚本当前为手臂设置了可伸缩的IK。 Using a distanceBetween the shoulder and the wrist (at a certain point, which is what i want to query) the bones would then stretch. 使用肩膀和手腕之间的距离(在某个点上,这是我要查询的),然后骨骼将伸展。 So obviously, I don't want to connect the two together. 很明显,我不想将两者连接在一起。

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')

Yes, your error makes perfect sense... The attribute you're looking for is actually just '.input1X' rather than '.input1.input1X' . 是的,您的错误很'.input1X' ……您要查找的属性实际上只是'.input1X'而不是'.input1.input1X'

I know, that isn't very clear, but you'll know in the future. 我知道,这还不是很清楚,但是将来您会知道的。 An easy way of figuring out stuff like this, by the way, is manually connecting stuff in Maya and seeing the MEL output in the script editor. 顺便说一句,弄清此类内容的一种简单方法是在Maya中手动连接内容,并在脚本编辑器中查看MEL输出。 You'll get the real deal every time, and translating that stuff to Python afterwards is quick. 您每次都会得到真正的一笔交易,然后将这些内容快速翻译成Python。

So : 因此

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

By the way, I'm not sure why you were assigning the result to input . 顺便说一句,我不确定为什么将结果分配给input I admit I'm not sure what that would return, but I don't see how it could be any useful! 我承认我不确定会返回什么,但是我看不出它有什么用!

Additionally : To answer your direct question, you can use getattr to query the value. 另外 :要回答您的直接问题,可以使用getattr查询值。

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

In my case, the variable being assigned to be set as the new attribute value was not being evaluated properly. 在我的情况下,被赋值设置为新属性值的变量没有得到正确评估。 setAttr interpreted the variable value as text, even though the value was input as a float value. 即使将值作为浮点值输入, setAttr将变量值解释为文本。

So, I simply assigned the variable and set it to float the variable within the command. 因此,我只是简单地分配了变量并将其设置为在命令内浮动该变量。 In my case, I did the following: 就我而言,我做了以下工作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM