Maya转换节点未出现在列表中

时间:2015-11-30 11:12:59

标签: python maya nurbs

下面的Maya python代码通过首先获取两个nurbs spheres,nurbsSphere1和nurbsSphere2的差异来给出nurbs布尔表面,以给出nurbs表面nurbsBooleanSurface1。然后它取得了这个表面和第三个球体nurbsSphere3的区别。结果,如在大纲中所见,是三个nurbs球体加上一个surfaceVarGroup,nurbsBooleanSurface1,其中父母'三个变换节点nurbsBooleanSurface1_1,nurbsBooleanSurface1_2和nurbsBooleanSurface1_3。

print(cmds.ls("nurbsBooleanSurface1_*", type="transform"))

Strangley(对我来说),list命令,cmds.ls(" nurbsBooleanSurface1 _ *",type =" transform")只产生[u' nurbsBooleanSurface1_1' ,u' nurbsBooleanSurface1_2'];缺少nurbsBooleanSurface1_3。

但是,在执行上述代码后,打印命令

print(cmds.ls("nurbsBooleanSurface1_*", type="transform"))

重新执行,结果是[u' nurbsBooleanSurface1_1',u' nurbsBooleanSurface1_2',u' nurbsBooleanSurface1_3']。

我尝试使用time.sleep(n)延迟执行最终打印命令无效。我已经想到了丢失的节点可能已经转移到另一个命名空间然后在执行块完成时重新出现(绝望,我知道!)。我已尝试使用函数和线程(后者仅表面上)重命名球体和曲面。第一次执行

时未列出的nurbsBooleanSurface1_3的原因
Array.prototype.every()

仍然是一个谜。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

一种肮脏的方式(但我唯一能找到的方法)是在脚本中调用cmds.refresh()

我在这里重写了你的剧本。请注意,我将每个球体存储在变量中,这是确保它可以工作的好习惯,即使现有对象已经被称为nurbsSphere3。

import maya.cmds as cmds

sphere1 = cmds.sphere(nsp=10, r=50)

sphere2 = cmds.sphere(nsp=4, r=5)
cmds.setAttr(sphere2[0] + ".translateX",-12.583733)
cmds.setAttr(sphere2[0] + ".translateY",-2.2691557)
cmds.setAttr(sphere2[0] + ".translateZ",48.33736)

nurbsBool1 = cmds.nurbsBoolean("nurbsSphere1", "nurbsSphere2", nsf=1, op=1)

sphere3 = cmds.sphere(nsp=4, r=5)
cmds.setAttr(sphere3[0] + ".translateX",-6.7379503)
cmds.setAttr(sphere3[0] + ".translateY",3.6949043)
cmds.setAttr(sphere3[0] + ".translateZ",49.40595)

nurbsBool2 = cmds.nurbsBoolean(nurbsBool1[0], sphere3[0], nsf=1, op=1)

cmds.refresh(currentView=True)  # Force evaluation, of current view only

print(cmds.listRelatives(nurbsBool2[0], children=True, type="transform"))

使用cmds.sphere()创建对象时,它会返回对象名称列表等。要访问它,您可以使用

mySphere = cmds.sphere()
print(mySphere)  
# Result: [u'nurbsSphere1', u'makeNurbSphere1']

print(mySphere[0])  # the first element in the list is the object name
# Result: nurbsSphere1

布尔运算也是如此。在返回值 http://help.autodesk.com/cloudhelp/2016/ENU/Maya-Tech-Docs/CommandsPython/index.html

下的命令文档中查找