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!