You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用PyMel查询Maya AnimLayers关联的所有对象与属性?

获取AnimLayer中带命名空间的完整属性路径

实现代码

import pymel.core as pm

def get_full_attr_paths_from_anim_layer(layer_name):
    anim_layer = pm.PyNode(layer_name)
    full_attr_paths = []
    
    # 获取动画层关联的所有动画曲线
    anim_curves = anim_layer.listConnections(type='animCurve', source=False, destination=True)
    
    for curve in anim_curves:
        # 反向追踪到源属性插头
        source_attr = curve.listConnections(source=True, destination=False, plugs=True)[0]
        attr_obj = source_attr.node()
        namespace = attr_obj.namespace()
        
        # 拼接完整路径
        if namespace:
            full_path = f"{namespace}:{attr_obj.name()}.{source_attr.attrName()}"
        else:
            full_path = f"{attr_obj.name()}.{source_attr.attrName()}"
        full_attr_paths.append(full_path)
    
    return full_attr_paths

# 示例:传入你的动画层名称
for attr_path in get_full_attr_paths_from_anim_layer('AnimLayer1'):
    print(attr_path)

关键细节

  • 用listConnections筛选动画层关联的animCurve,这些曲线是属性与动画层的关联桥梁
  • plugs=True参数确保拿到的是属性插头(而非节点),能直接提取属性名
  • namespace()方法自动处理命名空间,无命名空间时仅返回对象名+属性名
  • 最终输出格式完全匹配sph:sphere01.translateX这类需求

内容的提问来源于stack exchange,提问作者friendship.land

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 18:37:34