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云渲染66666 天前
GPT Image 2 + Seedance 2.0制作AI动漫短片教程
ai·blender·maya
成都渲染101云渲染666611 天前
CR15新功能介绍以及CR15云渲染流程
ue5·图形渲染·blender·maya·corona
3D小将1 个月前
Blender 模型转 glTF 2.0 完整技术手册(本地导出 +免费在线转换)
maya·solidworks模型·ug模型·stl模型
3D小将1 个月前
3D格式转换之3DXML 转换为 GLTF 技术文档
3d·maya·solidworks模型·ug模型·catia模型·stl模型
成都渲染101云渲染66661 个月前
极速渲染的办法,大量算力铺垫下的“云渲染”究竟有多快
ue5·maya
小年糕是糕手1 个月前
【Blender】建模篇终章最后一舞!手把手拿捏 Blender 卡通小狐狸建模(带你完整理清建模思路)
3dsmax·blender·maya
小年糕是糕手2 个月前
【Blender】Blender 曲线建模全解析:贝塞尔 / NURBS / 蒙皮 / 置换,从原理到实战
3dsmax·blender·maya
小年糕是糕手2 个月前
【Blender】Blender 树叶建模全攻略:3 种叶片 + 阵列 / 镜像 / 晶格工具实战精讲
3dsmax·blender·maya
3D小将2 个月前
模型格式转换之MAYA模型转换为GLTF格式技术文档
maya·solidworks模型·ug模型·sketchup模型·catia模型·stl模型
哎呦哥哥和巨炮叔叔2 个月前
Maya / Blender 云解析 | 渲染101一键提交,解析渲染更省心
云计算·blender·云渲染·maya·云解析·特效解算·影视动画云渲染