我想让maya检查列出的对象是否是一个混合形状节点。
这是我的代码:
def bake(self, *args):
self.items["selection"] = cmds.ls(sl = True)
self.items["shapes"] = cmds.listRelatives(self.items["selection"], ad = True)
shapes = ()
for i in self.items["shapes"]:
bs = cmds.listConnections(i, type = "blendShape", exactType = True)
if cmds.objectType(bs, isType = "blendShape"):
print bs
返回# Error: RuntimeError: file X:/Documents/maya/scripts\jtBakeCharacter.py line 16: No object name specified
第16行是:if cmds.objectType(bs, isType = "blendShape"):
除了我指定一个对象名称,该对象名称是bs ..我已经打印了bs的结果,并列出了许多对象。许多。
答案 0 :(得分:3)
代码是多余的。你不需要大部分线路。 listConnections 已经确保您只有混合形状。确切的问题是你在调用类似的东西:
cmds.objectType([])
对于一些额外的形状。这是非法的。但大多数代码可以封装如下:
selected = cmds.ls(sl = True, dag=True ,shapes = True)
blends = cmds.listConnections(selected , type = "blendShape", exactType = True)
for item in blends:
print item
但这可能无法完美地表达您的意图,但展示了您可能采取的额外步骤。实际上,如果cmds.objectType(bs,isType =“blendShape”)>>
,则不需要行>答案 1 :(得分:1)
Joojaa的答案很优雅,但你可以通过使用默认的选择行为来缩短它:
blendshapes = cmds.ls(cmds.listHistory(pdo=True), type='blendShape') or []
for item in blendshapes:
print item
(为了使它更短,我没有检查选择,所以如果没有选择任何选项,这个会失败)。
PS:如果你需要从其中一个上游形状进入混合形状而不是变形形状,你可以使用listHistory(f = True)
答案 2 :(得分:0)
你可以试试这个:
from pymel.core import *
for obj in selected():
shapeNode = obj.getChildren()[0]
for output in shapeNode.outputs():
if nodeType(output) == "blendShape":
print obj, "is a blendshape"