您好,我想知道是否有一种方法可以查询所有 callbacks
在Maya中创建的 **User Created ?同样,我是否可以查询连接到它们的对象或节点。我希望每次都更好地管理内存中的清洁度,并且不让任何回调在内存中丢失。**
import maya.cmds as cmds
import maya.OpenMaya as OpenMaya
##########################################
class MayaSignals(object):
def __init__(self):
super(MayaSignals)
self.callback_list = []
def setCallback(self, node):
sel = OpenMaya.MSelectionList()
sel.add(node)
obj = OpenMaya.MObject()
sel.getDependNode(0, obj)
idx = OpenMaya.MNodeMessage.addAttributeChangedCallback(obj, self.reading_node)
self.callback_list.append(idx)
def removeAllCallback(self):
for idx,itm in enumerate(self.callback_list):
print(idx, 'removed')
OpenMaya.MMessage.removeCallback(itm)
def reading_node(self, msg, plug, otherplug, *clientData):
if msg & OpenMaya.MNodeMessage.kAttributeSet:
print ('Attribute Changed On: %s' % plug.name())
if msg & OpenMaya.MNodeMessage.kConnectionMade:
print('Connection Created On: %s' % plug.name())
if msg & maya.OpenMaya.MNodeMessage.kConnectionBroken:
print ("Broken Connection On: %s" % plug.name())
################################################################################################
node = cmds.ls(sl=True)[0] #< ------ Node string type
#signal = MayaSignals() # class to manage the callbacks
#signal.setCallback(node)
signal # # # # to keep the instance alive
signal.removeAllCallback() # remove all into the array
# ---------------------------------------------`-`---------------------------------------------- #
在这里,我创建了一个示例,在该示例中,我将一个对象标记为回调,并在某些情况发生时打印一些内容。将每个回调 ID 添加到数组中以稍后将其删除。
我只需要一盏灯,即使是在C++中,我也可以在这里查看有关建议的文档。