我怎么选择的对象类型
我需要基本查询和执行基于当前的选择与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,这里的一切是一个简单的数据类型)。至少这是真实的与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
部分找到它们。
是的,但我无法得到这个工作在组件上,我怎么能从组件选择? – 2013-03-12 23:25:28
看我的编辑。 .. – Skurmedel 2013-03-12 23:49:23
您可以使用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命令参考中。
如果你问了一个问题,这将有所帮助。 – User 2013-03-09 13:37:53
我的标题是与说明相当自我解释,我需要找出'如何获得选定的对象类型' – 2013-03-09 23:34:15
为什么你会链接很多,如果命令,会不会更好地使用功能的字典? – joojaa 2013-03-10 09:12:35