首页 > 解决方案 > 在 Maya API 中选择顶点到边缘选择?

问题描述

我正在尝试将选择顶点转换为 Maya api 中的边选择……您有什么建议吗?

就像 cmds 中的 polyListComponentConversion 一样?:)

多谢!!

标签: pythonmaya

解决方案


一种方法是使用MItMeshVertex和收集连接的边:

import maya.api.OpenMaya as om

# Assume we've created a poly cube and selected vertices 2, 3, 5.
selection = om.MGlobal.getActiveSelectionList()

assert selection.length() == 1
node, component = selection.getComponent(0)

edges = set()
it = om.MItMeshVertex(node, component)
while not it.isDone():
    connected_edges = it.getConnectedEdges()
    edges.update(connected_edges)
    it.next()

print(edges)

这应该打印:

set([1, 2, 4, 5, 6, 7, 9])

polyListComponentConversion应该给出相同的结果:

cmds.select('pCube1.vtx[2:3]', replace=True)
cmds.select('pCube1.vtx[5]', add=True)
edges = cmds.polyListComponentConversion(fromVertex=True, toEdge=True)
print(edges)`
[u'pCube1.e[1:2]', u'pCube1.e[4:7]', u'pCube1.e[9]']

这扩展到同一组索引。


推荐阅读