Python; Moving PySegments on the timeline

Hi there! I’m very fresh to flame; and I’m trying to write some python code which will use the flame python API to move some PySegments around on the timeline, the same as dragging a segment around:

So far, reading the documentation and playing around in the script editor, I think that PySegment.change_start_frame might be the method that I want to accomplish this? It seems to work okay when I have a track with a single PySegment on it:

Here, I am able to set my start frame to the desired value. I did notice, however, that if I set the start frame this way, and then access the record_in attribute for my segment (which I believe gives me a PyTime for the segments start time in the track?) it doesn’t seem to change after running change_start_frame

Also, when there’s another segment on the same track, change_start_frame seems to have no effect:

Perhaps this is expected here, to avoid the first segment overlapping the second? Even so; it looks like this still does not work, even if there’s a gap large enough to accommodate the first segment:

Is anyone able to point me in the right direction here? I just want to be able to move some segments around using code, and I’m not seeing a clear way to do this using the API at present.

Im not terribly familiar with change_start_frame() but I think its more like a Reformat > Timecode/Keycode/Frame > Frame > Change Frame

Have a look at this repo, specifically the flatten_segments() method. Lifting and overwriting worked well for me.

PS - Please tell Tom S I say yoooo.

1 Like

Cheers, I’ll take a look at this, and pass that message along!!