• maya 设置半径 获取时长,设置时长


    maya 选择当前节点的所有子节点,设置半径,获取动画时长,并且设置时长

    python 脚本

    1. import maya.cmds as cmds
    2. # 获取当前选择的节点
    3. selected_nodes = cmds.ls(selection=True)
    4. # 创建一个列表来存储所需的节点:当前选中的节点及其所有后代
    5. nodes_to_select = list(selected_nodes) # 确保当前选择也被包含
    6. # 遍历每个已选择的节点并获取其所有后代节点
    7. for node in selected_nodes:
    8. # listRelatives命令用来获取节点的所有后代,allDescendents=True开启递归查询
    9. node_descendants = cmds.listRelatives(node, allDescendents=True) or []
    10. nodes_to_select.extend(node_descendants)
    11. # 过滤出有半径属性的节点
    12. nodes_with_radius = [node for node in nodes_to_select if cmds.attributeQuery('radius', node=node, exists=True)]
    13. # 设置所有有半径属性的节点的半径为0.01
    14. for node in nodes_with_radius:
    15. cmds.setAttr(node + ".radius", 0.01)
    16. # 可选:重新选择这些节点以便在界面上看到变化
    17. cmds.select(nodes_with_radius)
    18. def get_animation_length():
    19. # 获取场景中所有的动画曲线节点
    20. anim_curves = cmds.ls(type='animCurve')
    21. # 初始化最小和最大帧变量
    22. min_frame = float('inf')
    23. max_frame = float('-inf')
    24. # 遍历所有动画曲线
    25. for curve in anim_curves:
    26. # 获取每条曲线的关键帧时间
    27. keyframes = cmds.keyframe(curve, query=True)
    28. # 更新最小和最大帧数
    29. if keyframes:
    30. min_frame = min(min_frame, min(keyframes))
    31. max_frame = max(max_frame, max(keyframes))
    32. # 检查是否找到有效的帧数
    33. if min_frame == float('inf') or max_frame == float('-inf'):
    34. return 0
    35. else:
    36. return max_frame
    37. # 调用函数并打印结果
    38. end_frame=get_animation_length()
    39. print("end_frame",end_frame)
    40. start_frame = 1
    41. # 设置动画的实际播放范围
    42. cmds.playbackOptions(min=start_frame, max=end_frame)
    43. # 设置动画编辑器的时间范围(如果需要的话)
    44. cmds.playbackOptions(animationStartTime=start_frame, animationEndTime=end_frame)
    45. # 设置时间轴的显示范围
    46. cmds.playbackOptions(minTime=start_frame, maxTime=end_frame)

  • 相关阅读:
    Android PreferenceActivity添加ToolBar
    恢复出厂设置,手机数据还能“复活”?
    Python 解释器配置需要注意什么?
    小程序的性能优化
    20. 【Linux教程】emacs 编辑器
    RocketMQ高性能核心原理与源码架构剖析
    包装行业供应链集采管理系统:加强标准化建设,构建统一协同管控体系
    Git系列:rev-parse 使用技巧
    初始 Docker【介绍以及安装】
    【矩阵论】3. 矩阵运算与函数——矩阵函数的计算
  • 原文地址:https://blog.csdn.net/jacke121/article/details/138171781