Checking if channels are static

552 views
Skip to first unread message

Michał Frątczak

unread,
Apr 17, 2015, 5:29:34 AM4/17/15
to python_in...@googlegroups.com
Hello
Maya has an option to delete static curves from transfrormation channels (edit > delete by type > static channels).
Is there any method to check if they're static without deleting anything ?


Mahmoodreza Aarabi

unread,
Apr 17, 2015, 6:07:36 AM4/17/15
to python_in...@googlegroups.com

Hello
Static Channels are related to when you set a single keyframe on an object
when you want to delete it you can do it with the menu you want.but if you want to detect a static channel on an animation curve of an object you can use this code:

from maya import cmds

sels = cmds.ls(sl=True)
keyCount = 0
for each in sels:
    attrs = cmds.listAttr(each, k=True)
    for at in attrs:
        keyCount = cmds.keyframe((each + '.' + at), q=True, kc=True)
        if keyCount == 1:
            tempValue = cmds.getAttr(each + '.' + at)
            cmds.cutKey((each + '.' + at), cl=True)
            cmds.setAttr((each + '.' + at), tempValue)

main snippet is this keyCount = cmds.keyframe('object.attr', q=True, kc=True) that return count of your keyframes on an object.

good luck


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f8ad0153-0b12-4878-a117-7d8ab95be25a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--


Bests,
madoodia

f.michal

unread,
Apr 17, 2015, 6:14:21 AM4/17/15
to python_in...@googlegroups.com
Thanks !
But static channals are also those who have many keys all with the same values - which is my case.
Bigger picture: I'm trying to determine if camera moves or not in a shot.
If it's static there's a potential advantage in render frame range on some passes.

W dniu 2015-04-17 o 12:07, Mahmoodreza Aarabi pisze:

Mahmoodreza Aarabi

unread,
Apr 17, 2015, 6:37:49 AM4/17/15
to python_in...@googlegroups.com
can you share a simple scene that have the problem?

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--


Bests,
madoodia

f.michal

unread,
Apr 17, 2015, 6:56:22 AM4/17/15
to python_in...@googlegroups.com
As trivial as that MEL:

camera;
// Result: camera1 //
bakeResults -simulation true -t "1:24" -sampleBy 1 -disableImplicitControl true -preserveOutsideKeys true -sparseAnimCurveBake false -removeBakedAttributeFromLayer false -removeBakedAnimFromLayer false -bakeOnOverrideLayer false -minimizeRotation true -controlPoints false -shape true {"camera1"};
// Result: 18 //


W dniu 2015-04-17 o 12:37, Mahmoodreza Aarabi pisze:

Mahmoodreza Aarabi

unread,
Apr 17, 2015, 8:00:30 AM4/17/15
to python_in...@googlegroups.com
i reach to good result for this
but this mel code create a camera that all keyable attributes have key, also some attributes like Focal Length, F Stop and others have key too.
do you want the code apply on keyable attrs or all?


For more options, visit https://groups.google.com/d/optout.



--


Bests,
madoodia

Mahmoodreza Aarabi

unread,
Apr 17, 2015, 8:09:25 AM4/17/15
to python_in...@googlegroups.com

Test this on single and multiple static channels. it work on camera and its shape’s keys of attributes:

from maya import cmds

def detect_static_channel():
    sels = cmds.ls(sl=True)
    objs = []
    for each in sels:
        obj_shape = cmds.ls(shapes=True)[0]
        objs.append(each)
        objs.append(obj_shape)
        for o in objs:
            attrs = cmds.listAttr(o, k=True)
            for at in attrs:
                key_count = cmds.keyframe((o + '.' + at), q=True, kc=True)
                if key_count >= 1:
                    values = cmds.keyframe((o + '.' + at), q=True, vc=True)
                    value = cmds.keyframe((o + '.' + at), q=True, vc=True)[0]
                    if all(item == value for item in values) == True:
                        temp_value = cmds.getAttr(o + '.' + at)
                        cmds.cutKey((o + '.' + at), cl=True)
                        cmds.setAttr((o + '.' + at), temp_value)

detect_static_channel()

Good luck
:)

--


Bests,
madoodia

f.michal

unread,
Apr 17, 2015, 8:15:36 AM4/17/15
to python_in...@googlegroups.com
Thanks again !
But your code has fundamental flaw - it works only if there's exactly one key.
What if there are keys for every frame? And these keys have the same values - ergo camera is fixed in space ?
"Delete Static Channels" detects this. Of course I can iterate every keyframe checking if it's changing value, but (as lazy as I am :) ) I hoped for some existing command.
Maybe event smth. that's more clever than just keyframes (ie. checking parents or constraints).
Worst case scenario is playback entire shot range and watch for camera worldSpace movements - but this is unacceptable (playback can be slow in lighting scenes).


W dniu 2015-04-17 o 14:09, Mahmoodreza Aarabi pisze:

Marcus Ottosson

unread,
Apr 17, 2015, 8:33:10 AM4/17/15
to python_in...@googlegroups.com

I get what you’re after, and I don’t have an answer for you, but this..

playback can be slow in lighting scenes

..can be solved by either isolating the item or disabling viewport refresh before playing.

In case of heavy constraints, it’ll still be slow, but in those cases there might not be any other way around it anyway. Playing it through might even be the safest thing to do if you are actually looking to also detect motion coming in from constraints, scriptJobs and direct connections in addition to keys.



For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

f.michal

unread,
Apr 17, 2015, 8:38:32 AM4/17/15
to python_in...@googlegroups.com
W dniu 2015-04-17 o 14:33, Marcus Ottosson pisze:

I get what you’re after, and I don’t have an answer for you, but this..

playback can be slow in lighting scenes

..can be solved by either isolating the item or disabling viewport refresh before playing.

In case of heavy constraints, it’ll still be slow, but in those cases there might not be any other way around it anyway. Playing it through might even be the safest thing to do if you are actually looking to also detect motion coming in from constraints, scriptJobs and direct connections in addition to keys.



I guess you're right - this is safest, I'll have to consider this.
I already do isolate-playback-unisolate when baking cameras out and indeed this speeds up considerably.

thanks all !
-michal
Reply all
Reply to author
Forward
0 new messages