# Execute shortcut loop?

**URL:** <https://forum.logik.tv/t/execute-shortcut-loop/3643>\
**Category:** Python\
**Created:** [August 12, 2021, 5:26pm UTC](https://forum.logik.tv/t/execute-shortcut-loop/3643 "2021-08-12T17:26:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bryanb](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/bryanb/32/136_2.png) [@bryanb](https://forum.logik.tv/u/bryanb)\
**Post date:** [August 12, 2021, 5:26pm UTC](https://forum.logik.tv/t/execute-shortcut-loop/3643/1 "2021-08-12T17:26:05Z")

</div>

I’m trying to execute a shortcut on multiple segments. When this runs… I can see flame hitting the button multiple times on the first segment and not going to the next segment. Any idea what I’m missing? In my for loop I think it should hit the execute\_shortcut and then go back up to find and select the next segment.

```auto
def update_burnin(selection):
    import flame
    for shot in selection:
        for version in shot.versions:
            for track in version.tracks:
                for segment in track.segments:
                    for tlfx in segment.effects:
                        if tlfx.type == 'Burn-in Metadata':
                            segment.selected = True
                            flame.execute_shortcut ("Update (Button)")

```

---

<div class="post-metadata">

**Author:** ![PhilippeJ](https://avatars.discourse-cdn.com/v4/letter/p/a5b964/32.png) [@PhilippeJ](https://forum.logik.tv/u/PhilippeJ)\
**Post date:** [August 12, 2021, 6:50pm UTC](https://forum.logik.tv/t/execute-shortcut-loop/3643/2 "2021-08-12T18:50:24Z")

</div>

doing  
segment.selected = True  
adds to the selection but does not change the “current” segment, so instead try doing  
shot.selected\_segments = [segment]

If you have more then one “shot” in selection. You may need to open them as sequence or do a similar gymnastic with the flame.media\_panel.selected\_entries if the visible timeline is the “source” timeline.

---

<div class="post-metadata">

**Author:** ![bryanb](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/bryanb/32/136_2.png) [@bryanb](https://forum.logik.tv/u/bryanb)\
**Post date:** [August 12, 2021, 8:57pm UTC](https://forum.logik.tv/t/execute-shortcut-loop/3643/3 "2021-08-12T20:57:40Z")

</div>

Thanks Philippe. That makes sense. I have multiple sequences and they are all ‘open’ before trying the hook. It doesn’t appear to go to the next sequence.

In each sequence there is only one segment with Burn-In Metadata effect and that is the only soft effect on the segment And they are all named the same so I wonder if I should try to select that segment in each sequence by name.

---

<div class="post-metadata">

**Author:** ![PhilippeJ](https://avatars.discourse-cdn.com/v4/letter/p/a5b964/32.png) [@PhilippeJ](https://forum.logik.tv/u/PhilippeJ)\
**Post date:** [August 12, 2021, 10:25pm UTC](https://forum.logik.tv/t/execute-shortcut-loop/3643/4 "2021-08-12T22:25:45Z")

</div>

execute\_shortcut is a nice workaround for things missing in the python api but still a workaround. It execute the shortcut just like you had done it yourself, so if the currenlty shown sequence in the timeline is not change it will execute it over the same sequence. Opening the shot as sequence (even if it already an opened sequence ) before your version loop should make it the sequence displayed in the timeline.

---

<div class="post-metadata">

**Author:** ![bryanb](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/bryanb/32/136_2.png) [@bryanb](https://forum.logik.tv/u/bryanb)\
**Post date:** [August 12, 2021, 10:28pm UTC](https://forum.logik.tv/t/execute-shortcut-loop/3643/5 "2021-08-12T22:28:44Z")

</div>

ah nice. I’ll work on that.

---

<div class="post-metadata">

**Author:** ![PhilippeJ](https://avatars.discourse-cdn.com/v4/letter/p/a5b964/32.png) [@PhilippeJ](https://forum.logik.tv/u/PhilippeJ)\
**Post date:** [August 13, 2021, 11:07am UTC](https://forum.logik.tv/t/execute-shortcut-loop/3643/6 "2021-08-13T11:07:00Z")

</div>

try something like

```auto
def update_burnin(selection):
    import flame
    for shot in selection:
        shotname = shot.name.get_value()
        try:
            shot = shot.open_as_sequence()
            for version in shot.versions:
                for track in version.tracks:
                    for segment in track.segments:
                        for tlfx in segment.effects:
                            if tlfx.type == 'Burn-in Metadata':
                                shot.selected_segments = [segment]
                                flame.execute_shortcut ("Update (Button)")
        except:
            print("Had issues with %s"%(shotname))

```

The try-except will insure that if an error occur on a clip ( lock clip or segment ), the script will still continue to execute with the next clip.

---

<div class="post-metadata">

**Author:** ![bryanb](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/bryanb/32/136_2.png) [@bryanb](https://forum.logik.tv/u/bryanb)\
**Post date:** [August 13, 2021, 2:27pm UTC](https://forum.logik.tv/t/execute-shortcut-loop/3643/7 "2021-08-13T14:27:57Z")

</div>

This is perfect Philippe! Worked right away.

Thanks  
Bryan
