2013-05-06 62 views
1

我想让玛雅来检查列出的对象是否是一个Blendshape节点或不。Python玛雅 - 如果objectType返回“没有指定对象名称”

这是我的代码:

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"):

除了I AM指定对象名,对象名称是BS ..我有打印了bs的结果,并列出了许多对象。许多。

回答

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" 
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 =“形状融合”):任何东西

1

Joojaa的回答是优雅的,但你可以使用默认的选择行为得到它下来,甚至更短:

blendshapes = cmds.ls(cmds.listHistory(pdo=True), type='blendShape') or [] 
for item in blendshapes: 
    print item 

(在寻求使它更短,我不检查的选择,所以如果没有被选中这一项失败)。 PS:如果需要从上游形状之一到达混合形状,而不是变形形状,可以使用listHistory(f = True)