BakeResults how to specify current timeslider range

Hi,
i’m writing a script that performs the same as the menu in graph editor->curves->bake channel.

i’ve found that maya.cmds.bakeResults does this but i have 2 questions:

  • how do i set the “keep unbaked keys” to off from code
  • how do i specify the in time the current time range in the time slider?

Thanks

Thanks

  • how do i set the “keep unbaked keys” to off from code

preserveOutsideKeys is the flag you’re looking for. Defaults to True, setting it to False will get what you want.

  • how do i set the “keep unbaked keys” to off from code

time is the flag you’re looking for here.
If you need to get the values from the time slider, use cmds.playbackOptions. You’ll want the min/max flags.

So in the end you’d have something like this:


import maya.cmds as cmds
min_time = cmds.playbackOptions(q=True, min=True)
max_time = cmds.playbackOptions(q=True, max=True)

# You'll probably have more flags set depending on your other options.
cmds.bakeResults(preserveOutsideKeys=False, time=(min_time, max_time))

I already found it on the web, thanks mate, it’s exactly what i needed!
In the end i just query for the start = cmds.findKeyframe(sel, which=“first”) and end = cmds.findKeyframe(sel, which=“last”) and if start != end: cmds.bakeResults(…