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.

相关推荐
沟通qq 87622396512 天前
探索多旋翼飞行器:从设计到控制的全流程之旅
maya
hey2020052812 天前
如何将 Maya 首选项重置为默认值
动画·maya
成都渲染101云渲染666614 天前
三维制图软件哪个最好用?主流 3D 建模软件深度对比(2025)
3d·ue5·图形渲染·blender·maya·houdini
iesoxj15 天前
PS, Maya, UE 三端贴图对齐
贴图·maya
成都渲染101云渲染666619 天前
Maya动画渲染该用哪家云渲染?我用4家海内外Maya 云渲染平台做横评
maya
成都渲染101云渲染666619 天前
C4D 云渲染平台哪个好?价格、速度、稳定性全网真实对比(含渲染101)
ue5·图形渲染·blender·maya·houdini
成都渲染101云渲染666619 天前
Blender 云渲染平台实测对比:iRender、GarageFarm、渲染101 哪家更适合动画云渲染?
ue5·图形渲染·blender·maya·houdini
聊天QQ:6882388621 天前
探索单片LDO电源芯片:MC78PC00的魅力
maya
jtymyxmz22 天前
《Maya 2024 超级学习手册》3.4.8 实例:制作垃圾桶模型
学习·maya
jtymyxmz22 天前
《Maya 2024 超级学习手册》3.4.6 实例:制作小筐模型
学习·maya