Overwrite() and insert() behaving strangely

Wanted to see if anyone has any experience using the .overwrite() and insert() methods? I’ve been getting very strange and inconsistent results with them where the edit is being made at a totally different frame than the PyTime object I’m passing to it.

Here’s the script I’m trying to write. I want it to cut in reference for any unlinked clips it finds on the timeline. When I run it in the console it fetches the reference just fine but all the overwrites are done on a seemingly arbitrary frame.

import flame

tl = flame.projects.current_project.current_workspace.desktop.reel_groups[0].reels[0].sequences[-1]
ref_layer = tl.versions[0].tracks[0]
main_layers = tl.versions[1]

ref = flame.find_by_name(ref_layer.segments[1].name.get_value())[0]

for track in main_layers.tracks :
    for segment in track.segments :
        if segment.type == 'Unlinked Video' :
            ref.in_mark = segment.record_in
            ref.out_mark = segment.record_out + 1
            
            tl.overwrite(ref, segment.record_in, track)

For what it’s worth, I rewrote it using execute_shortcut() to trigger a normal overwrite like this and it works fine, but executes very slowly:

import flame

tl = flame.projects.current_project.current_workspace.desktop.reel_groups[0].reels[0].sequences[-1]
ref_layer = tl.versions[0].tracks[0]
main_layers = tl.versions[1]

ref = flame.find_by_name(ref_layer.segments[1].name.get_value())[0]

for track in main_layers.tracks :
    for segment in track.segments :
        if segment.type == 'Unlinked Video' :
            tl.in_mark = segment.record_in
            tl.primary_track = track
            
            ref.in_mark = segment.record_in
            ref.out_mark = segment.record_out + 1
            
            flame.execute_shortcut('Overwrite Edit')

Any idea what might be causing the first one to behave so unpredictably? is the overwrite() method maybe just busted?

I was going to suggest exactly what you did… try the execute_shortcut command.

I get some weirdness too trying to Insert/Overwrite. Because we can’t control the patching I can’t get overwrite / insert to be on the exact layer I want. You have to hope the patching is correct or run through hoops to manipulate it.

The only other thing I would look in to is the PyTime.frame_rate. But I don’t see you referencing any time based on a frame number or timecode. Not sure if that would help.