Copy key and paste keys from imported rig to referenced rig

167 views
Skip to first unread message

Utkarsh Agnihotri

unread,
Jun 28, 2021, 7:51:40 AM6/28/21
to Python Programming for Autodesk Maya
Hi everyone,
I am trying to copy keys from imported rig and paste it to the reference rig. I have written following code:

```  import pymel.core as pm

# select the ctrls to copy keys
sel = pm.ls("*CTRL")

print(sel)

# get a list of references
refs = pm.listReferences()

reference_namespaces = []

# get list of namespaces from reference
for ref in refs:
    reference_namespaces.append(ref.namespace)

# get time slider range of the scene
min_timeRange = pm.playbackOptions(q=1, min=1)
max_timeRange = pm.playbackOptions(q=1, max=1)

time_value = "{}:{}".format(min_timeRange, max_timeRange)
float_value = "{}:{}".format(min_timeRange, max_timeRange)

for s in sel:
    pm.copyKey(s, time=":", hierarchy="none", controlPoints=0, shape=1)
    for reference_namespace in reference_namespaces:
        if pm.objExists(reference_namespace + ":" + s):
            referenced_ctrl = reference_namespace + ":" + s
            pm.pasteKey(referenced_ctrl, option="replaceCompletely", float=(min_timeRange, max_timeRange),
                        time=(min_timeRange, max_timeRange), copies=1, connect=0)```

It is showing me following error:
# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
#   File "D:/Downloads/Scripts/Scripts/utkarsh/daily_scripts/transferKeys.py", line 29, in <module>
#     pm.pasteKey(referenced_ctrl, option="replaceCompletely", time=(min_timeRange, max_timeRange))
#   File "C:\Program Files\Autodesk\Maya2020\Python\lib\site-packages\pymel\core\animation.py", line 754, in pasteKey
#     res = cmds.pasteKey(*args, **kwargs)
#   File "C:\Program Files\Autodesk\Maya2020\Python\lib\site-packages\pymel\internal\pmcmds.py", line 130, in pasteKey_wrapped
#     res = new_cmd(*new_args, **new_kwargs)
# RuntimeError: time ranges not valid with given option # 

pastekey command seems to be the main issue and I checked with command page. I understand what is wrong with the command.
Please help!!



Justin Israel

unread,
Jun 28, 2021, 2:20:46 PM6/28/21
to python_in...@googlegroups.com
You have created these identical formatted strings:

    time_value = "{}:{}".format(min_timeRange, max_timeRange)
    float_value = "{}:{}".format(min_timeRange, max_timeRange)
 
But you never used them:

    pm.pasteKey(referenced_ctrl, option="replaceCompletely", float=(min_timeRange, max_timeRange),
                        time=(min_timeRange, max_timeRange), copies=1, connect=0)

Did you mean to pass time_value or float_value to the float/time parameters instead of the tuples?




--
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/c920bd24-d2dc-4218-9e17-47e56a469ed0n%40googlegroups.com.

Utkarsh Agnihotri

unread,
Jun 28, 2021, 4:58:56 PM6/28/21
to python_in...@googlegroups.com
Hi Justin,
Thanks for the reply.
Yes, float_value is not needed.

I was getting error when I was passing it as tuple or string.
 But the problem is solved now. I was using Pycharm and I had multiple windows open. For some reason, it was reading a scene from another window where there were no keys and it keep giving me errors.
After closing the other window, it worked as it is supposed to. 

Thanks once again :).


You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/DlgUhUYD6yo/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAPGFgA34ByLx%2Bh0zw8mLVbh%3DW5ToTujvFSgkP-o%3D_j_030ZWnQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages