我的节点repromesh中有56个对象。
我已经列出了该节点的所有属性,但是无法弄清楚如何删除一个(或所有)对象以将它们替换为另一个。
有一些属性,例如:instancedGroup.instancedMesh,但是找不到可访问的值/类型。
答案 0 :(得分:0)
非常复杂的一个:(编辑:删除所有底部的解决方案)
如果您转到此python文件(我在删除项目时通过打开echo all找到了该模块):
print(mash_repro_aetemplate.__file__)
您将找到mash脚本以及它们称为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
这是一种找到repro节点的方法:
widgets = get_maya_window().findChildren(qt.QWidget, 'AEMASH_ReproTemplate') or []
myRepro = widgets[0]
'myRepro'现在是mash repro节点的类。
代表您的节点的Qtreewidget是:
myRepro.objs_widget
您可以使用从qtree派生的另一个类:
# 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)