Maya转换节点未出现在列表中 [英] Maya transform node not appearing in list

查看:239
本文介绍了Maya转换节点未出现在列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的Maya python代码通过首先获取两个nurbs球体nurbsSphere1和nurbsSphere2的差来给出nurbs布尔表面,以给出nurbs曲面nurbsBooleanSurface1.然后,它获取此曲面与第三个球体nurbsSphere3的差.在大纲视图中可以看到,结果是三个nurbs球加上一个surfaceVarGroup nurbsBooleanSurface1,它们父"了三个变换节点nurbsBooleanSurface1_1,nurbsBooleanSurface1_2和nurbsBooleanSurface1_3.

The Maya python code below gives a nurbs boolean surface by first taking the difference of two nurbs spheres, nurbsSphere1 and nurbsSphere2, to give the nurbs surface nurbsBooleanSurface1. It then takes the difference of this surface and a third sphere, nurbsSphere3. The result, as seen in the outliner, is the three nurbs spheres plus a surfaceVarGroup, nurbsBooleanSurface1, which 'parents' three transform nodes nurbsBooleanSurface1_1, nurbsBooleanSurface1_2 and nurbsBooleanSurface1_3.

import maya.cmds as cmds

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

cmds.sphere(nsp=4, r=5)
cmds.setAttr("nurbsSphere2.translateX",-12.583733)
cmds.setAttr("nurbsSphere2.translateY",-2.2691557)
cmds.setAttr("nurbsSphere2.translateZ",48.33736)

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

cmds.sphere(nsp=4, r=5)
cmds.setAttr("nurbsSphere3.translateX",-6.7379503)
cmds.setAttr("nurbsSphere3.translateY",3.6949043)
cmds.setAttr("nurbsSphere3.translateZ",49.40595)

cmds.nurbsBoolean("nurbsBooleanSurface1", "nurbsSphere3", nsf=1, op=1)

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

(对我而言)Strangley,列表命令cmds.ls("nurbsBooleanSurface1_ *",type ="transform")仅产生[u'nurbsBooleanSurface1_1',u'nurbsBooleanSurface1_2'];缺少nurbsBooleanSurface1_3.

Strangley (to me), the list command, cmds.ls("nurbsBooleanSurface1_*", type="transform") only yields [u'nurbsBooleanSurface1_1', u'nurbsBooleanSurface1_2']; nurbsBooleanSurface1_3 is missing.

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

But when, after having executed the above code, the print command

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

重新执行,结果为[u'nurbsBooleanSurface1_1',u'nurbsBooleanSurface1_2',u'nurbsBooleanSurface1_3'].

is re-executed, the result is [u'nurbsBooleanSurface1_1', u'nurbsBooleanSurface1_2', u'nurbsBooleanSurface1_3'].

我尝试使用time.sleep(n)延迟执行最后的打印命令,但无济于事.我曾想过,丢失的节点可能会拆分成另一个名称空间,然后在执行块完成时重新出现(我知道,这很拼命!).我已经尝试过使用函数和线程(后者只是表面上的)来重命名球体和曲面.首次执行

I've tried delaying the execution of the final print command using time.sleep(n) to no avail. I've played with the idea that the missing node might have spun off into another namespace and then re-appeared at the completion of the execution block (desperate, I know!). I've experimented with renaming the spheres and surfaces, using functions and threads (the latter only superficially). The cause of the unlisted nurbsBooleanSurface1_3 on the first execution of

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

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

remains a mystery. Any help would be much appreciated.

推荐答案

一种肮脏的方法(但只有我能找到的方法)是在脚本执行期间调用cmds.refresh().

A dirty way (but only way I could find) is to call cmds.refresh() during the script.

我在这里重写了您的脚本.请注意,我将每个球体都存储在一个变量中,这是确保它可以正常工作的好习惯,即使现有对象已经被称为nurbsSphere3,也是如此.

I have rewritten your script here. Notice that I store each sphere in a variable, this is good practice to make sure it'll work, even if an existing object is already called nurbsSphere3 for example.

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()创建对象时,它将返回对象名称及更多内容的列表.要访问它,您可以使用

When you create an object using cmds.sphere() it returns a list of the object name and more. To access this, you can use

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

The same is true for the boolean operation. Look in the documentation for the command under Return value http://help.autodesk.com/cloudhelp/2016/ENU/Maya-Tech-Docs/CommandsPython/index.html

这篇关于Maya转换节点未出现在列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆