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.

相关推荐
3D小将1 天前
MAYA模型转换为GLTF格式技术文档(推荐免费在线格式转换)
maya·solidworks模型·ug模型·sketchup模型·catia模型·stl模型
成都渲染101云渲染666611 天前
Maya 云渲染太慢怎么办?渲染 101 云渲染:从 “按天等” 到 “按小时出” 的高效方案
maya
成都渲染101云渲染666617 天前
C4D/Blender云渲染计费详解|5090显卡实测:速度对比+成本核算
3d·ue5·blender·maya·houdini
hey2020052819 天前
Houdini渲染农场哪个好用?
动画·blender·maya·3d渲染·houdini·cinema4d
CG_MAGIC1 个月前
Maya 角色绑定:控制器搭建与 IK/FK 切换
3d·贴图·maya·渲云渲染
ZAEQgyKFs2 个月前
探索AB胶刮胶机的技术实现:基于C#上位机与研华运动控制卡
maya
CG_MAGIC2 个月前
Substance Painter 高效出图:贴图导出与后期优化技巧
3d·贴图·maya·substance painter·渲云渲染·3d软件
哎呦哥哥和巨炮叔叔2 个月前
程序化纹理(Procedural Texture)详解:3D项目体积缩减90%,云渲染效率全面提升
blender·maya·渲染101云渲染·材质系统·arnold渲染·程序化纹理·cg工作流
成都渲染101云渲染66662 个月前
渲染速度慢怎么办?如何将 Maya 渲染速度提升成百上千倍(通用方法)
人工智能·图形渲染·blender·maya·houdini
哎呦哥哥和巨炮叔叔2 个月前
Cinema 4D 与 Maya 全面对比:3D 动画与设计该如何选择?
云渲染·maya·三维动画·渲染101·动态设计·cinema 4d·3d软件对比