Select the key only on the active channel

Select the key only on the active channel

dg3duy
Collaborator Collaborator
311 Views
2 Replies
Message 1 of 3

Select the key only on the active channel

dg3duy
Collaborator
Collaborator

How is it possible to select the key only on the active channel and not on all other channels?

cmds.selectKey(time=(cmds.currentTime(q=1), cmds.currentTime(q=1)))

This code is thanks to the user of this forum mcw0
keys channel.gif

0 Likes
Accepted solutions (1)
312 Views
2 Replies
Replies (2)
Message 2 of 3

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

The problem with this, is that you first need to know if the grapheditor exists, then you need to know if a curve is shown in the grapheditor. If one of these is not the case the script would throw an error that a normal user wouldn't understand. So you have to either add special error messages or result to just selecting every channel on the selected object again.

 

with custom error messages:

import maya.cmds as cmds

if cmds.ls(sl = True) != None:
    if cmds.animCurveEditor( 'graphEditor1GraphEd', exists=True ) == True:
        channels = cmds.animCurveEditor('graphEditor1GraphEd',q= True, cs = True)
        if channels != None:
            for c in channels:
                cmds.selectKey(c, time=(cmds.currentTime(q=1), cmds.currentTime(q=1)), add = True)
        else:
            cmds.error("No channel shown in Graph Editor")
    else:
        cmds.error("No existing Graph Editor found")
else:
    cmds.error("No object selected")

 

with defaulting to selecting every channel on selected objects:

import maya.cmds as cmds

if cmds.ls(sl = True) != None:
    if cmds.animCurveEditor( 'graphEditor1GraphEd', exists=True ) == True and cmds.animCurveEditor('graphEditor1GraphEd',q= True, acs = True) ==True:
        channels = cmds.animCurveEditor('graphEditor1GraphEd',q= True, cs = True)
        for c in channels:
            cmds.selectKey(c, time=(cmds.currentTime(q=1), cmds.currentTime(q=1)), add = True)

    else:
        cmds.selectKey(time=(cmds.currentTime(q=1), cmds.currentTime(q=1)), add = True)

 

I hope it helps!

Message 3 of 3

dg3duy
Collaborator
Collaborator

@Kahylan it's a very good explanation, thank you very much! it's perfectly what I was needing to use.

0 Likes