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.

相关推荐
CG_MAGIC3 天前
Substance Painter 高效出图:贴图导出与后期优化技巧
3d·贴图·maya·substance painter·渲云渲染·3d软件
哎呦哥哥和巨炮叔叔6 天前
程序化纹理(Procedural Texture)详解:3D项目体积缩减90%,云渲染效率全面提升
blender·maya·渲染101云渲染·材质系统·arnold渲染·程序化纹理·cg工作流
成都渲染101云渲染66667 天前
渲染速度慢怎么办?如何将 Maya 渲染速度提升成百上千倍(通用方法)
人工智能·图形渲染·blender·maya·houdini
哎呦哥哥和巨炮叔叔7 天前
Cinema 4D 与 Maya 全面对比:3D 动画与设计该如何选择?
云渲染·maya·三维动画·渲染101·动态设计·cinema 4d·3d软件对比
CG_MAGIC8 天前
Maya 关键帧动画基础:角色走路循环与姿态调整
3d·maya·效果图·建模教程·渲云渲染·渲云
哎呦哥哥和巨炮叔叔8 天前
Maya 角色绑定效率提升:免费 Mansur-Rig 模块化绑定工具详解 + 云渲染方案推荐
云渲染·maya·rigging·渲染101·角色绑定·mansur-rig·cg制作
哎呦哥哥和巨炮叔叔8 天前
使用 Maya 进行动态设计的最佳方法总结(Motion Design 高效流程解析)
云渲染·maya·渲染101·动态设计·arnold渲染·motion design·mash动画
cvcNYgAdnd10 天前
电力系统连续潮流计算/ Matlab编程 1.绘制电力系统任意节点完整的PV曲线(PV curve)
maya
CG_MAGIC10 天前
Maya 角色绑定基础:骨骼搭建与权重绘制避坑要点
3d·maya·渲云渲染·3d软件
jtymyxmz13 天前
《Maya 2024 超级学习手册》3.4.9 实例:制作锤子模型
学习·maya