2013-05-06 35 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)