Maya Python:“选择y=0以下的所有顶点”

2024-09-30 04:29:25 发布

您现在位置:Python中文网/ 问答频道 /正文

使用玛雅.cmds,我想选择y=0以下的所有顶点,以便删除它们。我该如何实现这一点?另外,我正在处理大量的.obj网格,因此我需要迭代每个网格并执行相同的操作。要遍历每个文件,我应该使用什么技术?在

import maya.cmds as cmds
import maya.api.OpenMaya as om2

# Select all objects
selection = cmds.select(all = True)
# Rotate -90 degrees on the x axis
# cmds.rotate(-90)

def vertexOm2():
    """
    Using Maya Python API 2.0
    """
    #___________Selection___________
    # 1 # Query the selection list
    selectionLs = om2.MGlobal.getActiveSelectionList()

    # 2 # Get the dag path of the first item in the selection list
    selObj = selectionLs.getDagPath(0)

    #___________Query vertex position ___________
    # create a Mesh functionset from our dag object
    mfnObject = om2.MFnMesh(selObj)

    return mfnObject.getPoints()

vertexOm2()

返回“TypeError:item不是DAG路径”

或使用命令:

^{pr2}$

我都是从here那里得到的。在


Tags: theimport网格asallitemquerylist
1条回答
网友
1楼 · 发布于 2024-09-30 04:29:25

如果你想得到答案,你至少应该发布一段代码。 你的问题:

How would I implement this?

只是:执行for循环来遍历对象。在

Also, I'm processing a large number of .obj meshes

xform和createMayaRanges函数用于回答此问题,但您可能会调查maya API

To iterate through each file, what technique should I use?

手动执行,或在maya会话或最后一个解决方案内执行循环,使用mayapy,但这需要大量的工作。 有关批处理maya文件的详细信息:

http://www.toadstorm.com/blog/?p=136

import itertools
import maya.cmds as cmds

sel = cmds.ls(sl=True)

def createMayaRanges(i):
    output = []
    for a, b in itertools.groupby(enumerate(i), lambda (x, y): y - x):
        b = list(b)
        myString = '{0}:{1}'.format(b[0][1], b[-1][1])
        output.append(myString)
    return output

output_sel = []
for obj in sel:
    coord = cmds.xform('{}.vtx[:]'.format(obj),
                         q=1,
                         ws=1,
                         t=1)
    coordY = coord[1::3]
    index_lower = [x for (x,i) in enumerate(coordY) if i < 0]
    optimized_sel = createMayaRanges(index_lower)
    selToString = ['{}.vtx[{}]'.format(obj, j) for j in optimized_sel]
    if selToString:
        output_sel += selToString

cmds.select(output_sel)

相关问题 更多 >

    热门问题