Maya监听 DAG events

In Maya, the OpenMaya API provides several classes to listen to different kinds of events including DAG events. MNodeMessage class is responsible for tracking the changes of DAG nodes.

Here's an example of how to set up a callback to listen for name changes of a DAG node:

复制代码
import maya.OpenMaya as om

def nodeChangedCallback(msg, plug, otherPlug, userData):
    if msg & om.MNodeMessage.kConnectionMade:
        print("Connection made.")
    elif msg & om.MNodeMessage.kConnectionBroken:
        print("Connection broken.")
    # More event types can be handled here

# Suppose the DAG node we're interested in is "pCube1"
node = om.MSelectionList()
om.MGlobal.getSelectionListByName("pCube1", node)
obj = om.MObject()
node.getDependNode(0, obj)

callbackId = om.MNodeMessage.addNodeChangedCallback(obj, nodeChangedCallback)

In the code above, nodeChangedCallback will be called when connect/disconnect events occur to "pCube1".

To stop listening, you can use om.MMessage.removeCallback(callbackId). Please remember to remove your callbacks when they're no longer needed because they will persist across different sessions in Maya, and you might encounter performance issues or unexpected behavior if you don't.

For listening to DAG-related changes like child added/removed, parent added/removed etc, instead of addNodeChangedCallback, methods like addParentAddedCallback, addParentRemovedCallback, addChildAddedCallback, addChildRemovedCallback etc in MNodeMessage can be used.

This should give you a basic idea. For a complete list of available messages/callbacks, refer to the official Maya API documentation. Please note that API-based solutions might be a bit overkill for something simple or if you don't plan to use it extensively, as it's much lower-level compared to using python commands or mel commands directly.

相关推荐
成都渲染101云渲染66665 天前
【无标题】
maya
成都渲染101云渲染66669 天前
blender云渲染指南2025版
前端·javascript·网络·blender·maya
渲染101专业云渲染25 天前
川翔云电脑32G大显存集群机器上线!
云计算·电脑·blender·maya·houdini
子燕若水1 个月前
修改maya小部件操作器(manipulator,那个带有箭头和圆环的小部件坐标轴)
maya
子燕若水2 个月前
Maya软件中的约束基础:提高角色动画制作效率的关键技术
maya
子燕若水2 个月前
maya调整全局关节显示大小
maya
渲染101专业云渲染2 个月前
分布式渲染与云渲染:技术与应用的黄金搭档
服务器·分布式·电脑·blender·maya·houdini
渲染101专业云渲染2 个月前
3ds Max 2026 新功能全面解析
3d·云计算·blender·maya·houdini
渲染101专业云渲染2 个月前
Blender4.4正式发布:核心更新与渲染101云渲染平台应用指南
3d·云计算·blender·maya·houdini
ui设计前端开发老司机2 个月前
数字孪生的建模师blender和maya你更喜欢用哪个?
blender·maya