簡體   English   中英

如何獲取選定的對象類型

[英]How do I Get The Selected Object type

我基本上需要根據當前選擇的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命令。

PyMEL將為您轉換選擇列表到節點(與MEL不同,在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部分下找到它們。

您可以使用maya本機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命令參考。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM