# Python Script

**URL:** <https://forum.logik.tv/t/python-script/11889>\
**Category:** Python\
**Tags:** python\
**Created:** [December 17, 2024, 9:28am UTC](https://forum.logik.tv/t/python-script/11889 "2024-12-17T09:28:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuuta1484](https://avatars.discourse-cdn.com/v4/letter/y/858c86/32.png) [@yuuta1484](https://forum.logik.tv/u/yuuta1484)\
**Post date:** [December 17, 2024, 9:28am UTC](https://forum.logik.tv/t/python-script/11889/1 "2024-12-17T09:28:12Z")

</div>

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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![john-geehreng](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/john-geehreng/32/7195_2.png) [@john-geehreng](https://forum.logik.tv/u/john-geehreng)\
**Post date:** [December 17, 2024, 11:05am UTC](https://forum.logik.tv/t/python-script/11889/2 "2024-12-17T11:05:50Z")

</div>

I’ve done something similar, so you could try this: [Trimming shots - #3 by john-geehreng](https://forum.logik.tv/t/trimming-shots/6038/3)

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

---

<div class="post-metadata">

**Author:** ![knhn](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/knhn/32/5635_2.png) [@knhn](https://forum.logik.tv/u/knhn)\
**Post date:** [December 17, 2024, 3:16pm UTC](https://forum.logik.tv/t/python-script/11889/3 "2024-12-17T15:16:04Z")

</div>

Please fix the formatting of your post.

```auto
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

```auto
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.

```auto
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](https://github.com/khanrahan/set-in-out-marks) or availble on logik portal). Though I do need to update it to work with 2025.

Hope some of this helps! 🔥

---

<div class="post-metadata">

**Author:** ![yuuta1484](https://avatars.discourse-cdn.com/v4/letter/y/858c86/32.png) [@yuuta1484](https://forum.logik.tv/u/yuuta1484)\
**Post date:** [December 18, 2024, 1:36am UTC](https://forum.logik.tv/t/python-script/11889/4 "2024-12-18T01:36:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yuuta1484](https://avatars.discourse-cdn.com/v4/letter/y/858c86/32.png) [@yuuta1484](https://forum.logik.tv/u/yuuta1484)\
**Post date:** [December 18, 2024, 2:10am UTC](https://forum.logik.tv/t/python-script/11889/5 "2024-12-18T02:10:00Z")

</div>

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.
