Python Script

I’m a beginner of Python script. My final goal is to trim top 24 flame (slate) and tail 24 flame (black) with a python script. I’ve tried some basic python coding, right now I’m facing custom UI problem.

I got script_to_change_segment_colors from Andy. I copied the structure of it and change it to script to change clip colors for a baby step. Here is the script:

def scope_clip(selection):
    import flame

    for item in selection:
        if isinstance(item, flame.PyClip):
            return True
        return False

def red(selection):
    import flame

    for clip in selection:
        clip.colour = (0.5, 0.0, 0.0)

def get_timeline_custom_ui_actions():
    return [
        {
            'name': 'Color Clip',
            'actions': [
                {
                    'name': 'Red',
                    'isVisible': scope_clip,
                    'execute': red,
                    'minimumVersion': '2020'
                }
            ]
        }
    ]

But it Color Clip doesn’t appear when right-clicking the selected clip.
Someone help me?

I’ve done something similar, so you could try this: Trimming shots - #3 by john-geehreng

But it might be easier scripting-wise to set in and out points and then do an overwrite.

Please fix the formatting of your post.

get all of your code inside the triple backticks like this

Taking a look… you are defining a timeline right click menu action that only appears for PyClip objects… but i think in a timeline with multiple shots… you could have PySegment objects and thats why its not appearing perhaps? It would only be a PyClip if its a timeline with 1 shot, 2 or more shots = PySegments.

So maybe try

def scope_timeline_object(selection):                                                   
    """Filter out only supported Timeline objects."""                                   
    valid_objects = (                                                                   
            flame.PyClip,                                                               
            flame.PySegment)                                                            
                                                                                        
    return all(isinstance(item, valid_objects) for item in selection) 

Or if you are doing a typical shift selection for a bunch of shots in a timeline, its actually going to include the PyTransition objects in between each shot as well. So you would need to include that in your filter, and then skip over transitions in your red() function.

def scope_timeline_object(selection):                                                     
    """Filter for PySegments or PyTransitions.                                          
                                                                                        
    PyTransitions are included because typical box or shift + click selections will     
    include them.                                                                       
    """                                                                                 
    valid_objects = (                                                                   
            flame.PySegment,                                                            
            flame.PyTransition)                                                         
                                                                                        
    return all(isinstance(item, valid_objects) for item in selection)

And then, I dont quite understand your final goal… but maybe instead of trimming, just set in & out on your timelines and then export using Export Between Marks would be an easier workflow. I have a script that sets in/out or clears them on all selected timelines (link to github or availble on logik portal). Though I do need to update it to work with 2025.

Hope some of this helps! :fire:

1 Like

My bad, I fixed it. I’ll try what you give me.
My post studio gave me the weird instruction that you need to do hard commit on the top track of timelines and trim out timeline elements like slate and black frames before exporting. They think that prevents audio sub-frame shift when exporting.

Thanks!
That’s pretty close to what I want. Only difference is I want to trim the audio track as well as video track. I will tweak it.

1 Like