1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

python maya get min max key frame

Last updated at Posted at 2023-06-30
def GetAllByType(selType="joint"):
    all_curves = cmds.ls(type=selType, ni=True, o=True, r=True, l = True)
    curves_transforms = cmds.listRelatives(all_curves, p=True, type = "transform")
    return curves_transforms


def GetMinMaxFrame(selType="joint"):
    import math
    joints = GetAllByType(selType)
    minKey = 10000
    maxKey = 0
    for joint in joints:
        all_keys = sorted(cmds.keyframe(joint, q=True) or [])  # Get all the keys and sort them by order. We use `or []` in-case it has no keys, which will use an empty list instead so it doesn't crash `sort`.
        if all_keys:  # Check to see if it at least has one key.
            if all_keys[0] < minKey: minKey = all_keys[0]
            if all_keys[-1] > maxKey: maxKey = all_keys[-1]
    return math.floor(minKey), math.ceil(maxKey)
min, max = GetMinMaxFrame()
print(min, max)
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?