2013-03-09 49 views
1

我需要基本查詢和執行基於當前的選擇與PYMEL,例如幾個任務:我怎麼選擇的對象類型

from pymel.core import *  
s = selected() 
if (s.selType() == 'poly'): 
    #do something  
if (s.selType() == 'surface'): 
    #do something  
if (s.selType() == 'cv'): 
    #do something  
if (s.selType() == 'vertex'): 
    #do something  
if (s.selType() == 'face'):  
    #do something 
if (s.selType() == 'edge'): 
    #do something 
if (s.selType() == 'curve'): 
    #do something 

我知道selType()不是實際pymel功能,我也想利用pymels api命令,如果有意義的話,不要使用標準的mel命令。

+2

如果你問了一個問題,這將有所幫助。 – User 2013-03-09 13:37:53

+0

我的標題是與說明相當自我解釋,我需要找出'如何獲得選定的對象類型' – 2013-03-09 23:34:15

+0

爲什麼你會鏈接很多,如果命令,會不會更好地使用功能的字典? – joojaa 2013-03-10 09:12:35

回答

1

PyMEL將轉換的選擇列表供您節點(不同於MEL,這裏的一切是一個簡單的數據類型)。至少這是真實的與ls和相關命令(selected只是ls(sl=True))在

一切列表將是PyNode的一個子類,所以你可以依靠他們有一個方法nodeType

從那裏,很容易處理每個選擇根據其類型。


組件從pymel.core.Component繼承,並且對於每種組件類型一類;例如,MeshVertex

您可以使用isinstance(obj, type_sequence)過濾掉部分組成:

filter(lambda x: isinstance(x, (pm.MeshVertex, pm.MeshEdge, pm.MeshFace)), pm.selected()) 

您可以在在PyMEL文檔的general部分找到它們。

+0

是的,但我無法得到這個工作在組件上,我怎麼能從組件選擇? – 2013-03-12 23:25:28

+0

看我的編輯。 .. – Skurmedel 2013-03-12 23:49:23

1

您可以使用maya native filterExpand命令將每個排序到它們各自的類型中。 它主要是通過選擇篩選並使得對應於你正在尋找

例如類型的對象的列表:

import maya.cmds as cmds 

selection = cmds.ls(sl=1) # Lists the current selection and 
          # stores it in the selection variable 

polyFaces = cmds.filterExpand(sm=34) # sm (selectionMask) = 34 looks for polygon faces. 
            # Store the result in polyFaces variable. 

if (polyFaces != None): # If there was any amount of polygon faces. 
    for i in polyFaces: # Go through each of them. 
     print(i)   # And print them out. 

的命令更多的信息和相應的INT-值過濾器在python或mel命令參考中。

相關問題