在 Maya 中,如何使用 python 删除节点 Mash/Repro 中的某些对象?

In Maya, how can I delete with python some object in the node Mash/Repro?

我的节点 repromesh 中有 56 个对象。

我已经列出了这个节点的所有属性,但不知道如何删除一个(或所有)对象以便用另一个对象替换它们。

有一些属性,例如:instancedGroup.instancedMesh 但没有 value/type 我可以找到访问它。

enter image description here

相当复杂:(编辑:删除底部所有内容的解决方案

如果你转到这个 python 文件(我通过打开 echo all 找到这个模块,同时删除项目):

print(mash_repro_aetemplate.__file__)

您会找到混搭脚本和他们称之为 UI 的片段。

import maya.OpenMayaUI as mui
from shiboken2 import wrapInstance 

usingPyside2 = False
try:
    import PySide2
    usingPyside2 = True
except:
    pass
from flux.imports import *
from flux.core import pix
import flux.core as fx

import mash_repro_utils
from mash_repro_icons import MASH_REPRO_ICONS

from functools import partial
import MASH.undo as undo

def get_maya_window():
    ptr = mui.MQtUtil.mainWindow()
    if ptr is not None:
        return wrapInstance(long(ptr), qt.QMainWindow)

def refresh_all_aetemplates(force=False):
    """ Refresh all the repro aetemplates"""
    widgets = get_maya_window().findChildren(AEMASH_ReproTemplate) or []
    for widget in widgets:
        global SCENE_OPENED
        SCENE_OPENED = True
        widget.update_data(widget.node, force=force)
        SCENE_OPENED = False

这里有一种找到重现节点的方法:

widgets = get_maya_window().findChildren(qt.QWidget, 'AEMASH_ReproTemplate') or []
myRepro = widgets[0]

'myRepro' 现在是 mash 重现节点的 class。

代表您的节点的 Qtreewidget 是:

myRepro.objs_widget

您可以使用从 qtree 派生的另一个 class :

# work only on selection, if you want to modify this command, maybe create your own add_sel_bjects(self, objs=[])
myRepro.objs_widget.add_objects()


# work only on the selection in the qtree widget
myRepro.objs_widget.delete_item()

# you can use qtree functions instead :
# myRepro.objs_widget.clear()
items_count = myRepro.objs_widget.topLevelItemCount()

在delete_item方法中,有这个

mash_repro_utils.remove_mesh_group(myRepro.objs_widget.node, id)
mash_repro_utils.remove_proxy_group(self.node, self.instance_index, id)

我没有时间去调查,但从那里,你会发现:

print(mash_repro_utils.__file__)
# Result: 'maya_path/plug-ins/MASH/scripts/mash_repro_utils.py' # 

去那里,那里有所有 maya python mash 函数:

def remove_proxy_group(mash_repro_node, instance_index, index):
    """
    Remove a proxy object from the Repro node

    :param mash_repro_node: MASH Repro node
    :param instance_index: Object index
    :param index: Proxy index
    :return: None
    """
    with ReproUpdating(mash_repro_node):
        data = get_data_layout(mash_repro_node)
        indices = data[instance_index]['proxies'].keys()
        indices.sort()
        if index in indices:
            position = indices.index(index)
            for i in range(position, len(indices)):
                clean_proxy_index(mash_repro_node, instance_index, indices[i])
            for i in range(position + 1, len(indices)):
                if 'group' in data[instance_index]['proxies'][indices[i]]:
                    new_index = connect_proxy_group(mash_repro_node, data[instance_index]['proxies'][indices[i]]['group'], instance_index)
                    maya.cmds.setAttr("%s.instancedGroup[%d].proxyGroup[%d].proxyLod" % (mash_repro_node, instance_index, new_index), data[instance_index]['proxies'][indices[i]]['proxyLod'])
                    hasMASHFlag = maya.cmds.objExists('%s.mashOutFilter' % (data[instance_index]['proxies'][indices[i]]['group']))
                    if hasMASHFlag:
                        maya.cmds.deleteAttr( data[instance_index]['proxies'][indices[i]]['group'], at='mashOutFilter' )

您应该可以从那里进行调查。

你也可以自己制作 delete_all,像这样:

items_count = myRepro.objs_widget.topLevelItemCount()
for id in sorted(range(items_count), reverse=True):
    mash_repro_utils.remove_mesh_group(myRepro.objs_widget.node, id)
    myRepro.objs_widget.obj_dropped.emit(None)