Move keys... references error.

Move keys... references error.

dg3duy
Collaborator Collaborator
292 Views
1 Reply
Message 1 of 2

Move keys... references error.

dg3duy
Collaborator
Collaborator

The following script moves the keys to the timeline, but it does it in referenced objects without problems, but if these referenced objects have locked keys an error appears, the question is how should be the code to ignore the objects that contain locked keys?

import pymel.core as pm

objects = pm.ls(sl=1)
attrs = pm.selectionConnection('graphEditor1FromOutliner', q=1, object=1)
currentTime = pm.currentTime()

targetAttr = None
if len(attrs) == 1:
    buffer = attrs[0].split(".")
    if len(buffer) > 1:
        targetAttr = buffer[1]

for obj in objects:
    attrs = pm.listAttr(obj, keyable=True)
    for attr in attrs:
        if targetAttr and attr != targetAttr:
            continue
        nodes = pm.keyframe(obj, attribute=attr, q=True, name=True)
        if nodes:
            minTime = min(pm.keyframe(obj, attribute=attr, q=True))
            pm.keyframe(obj, attribute=attr, edit=True, relative=True, timeChange=currentTime - minTime)

locked keys.gif

 

0 Likes
Accepted solutions (1)
293 Views
1 Reply
Reply (1)
Message 2 of 2

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

Maya already automatically skips the affected attributes and moves the attributes that it can. All this is is an autimatical warning that gets printed out if the keyframe command can't execute properly, so really not much to worry about since the script works properly for the attributes that it can move.

 

If the warnings annoy you, you could temporarily surpress them in your script as explained in this thread:

 

https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11712848

 

But it is important that you reset the scripteditor settings at the end of your script, because having warnings turned off during general work with maya isn't a good idea.

 

I hope it helps!