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.

相关推荐
小年糕是糕手2 天前
【Blender】Blender 曲线建模全解析:贝塞尔 / NURBS / 蒙皮 / 置换,从原理到实战
3dsmax·blender·maya
小年糕是糕手3 天前
【Blender】Blender 树叶建模全攻略:3 种叶片 + 阵列 / 镜像 / 晶格工具实战精讲
3dsmax·blender·maya
3D小将7 天前
模型格式转换之MAYA模型转换为GLTF格式技术文档
maya·solidworks模型·ug模型·sketchup模型·catia模型·stl模型
哎呦哥哥和巨炮叔叔11 天前
Maya / Blender 云解析 | 渲染101一键提交,解析渲染更省心
云计算·blender·云渲染·maya·云解析·特效解算·影视动画云渲染
成都渲染101云渲染666618 天前
Maya软件常用云渲染平台2026版本
maya
3D小将1 个月前
MAYA模型转换为GLTF格式技术文档(推荐免费在线格式转换)
maya·solidworks模型·ug模型·sketchup模型·catia模型·stl模型
成都渲染101云渲染66661 个月前
Maya 云渲染太慢怎么办?渲染 101 云渲染:从 “按天等” 到 “按小时出” 的高效方案
maya
成都渲染101云渲染66661 个月前
C4D/Blender云渲染计费详解|5090显卡实测:速度对比+成本核算
3d·ue5·blender·maya·houdini
hey202005281 个月前
Houdini渲染农场哪个好用?
动画·blender·maya·3d渲染·houdini·cinema4d
CG_MAGIC2 个月前
Maya 角色绑定:控制器搭建与 IK/FK 切换
3d·贴图·maya·渲云渲染