A PyTime question and a flame.execute_shortcut question

Is there any way for PyTime to reference the last frame of a clip?

Is there any way to use the new execute_shortcut with multiple selections?

You can get the last frame via segment.record_out or segment.source_out, depending on your needs. This will return a PyTime object. So segment.record_out.frame would give you the frame, segment.record_out.timecode would give you the timecode.

https://help.autodesk.com/view/FLAME/2022/ENU/?guid=Flame_API_Python_API_autodesk_flame_python_api_html#PySegment

Can you elaborate what you mean by multiple selections for the shortcut? :slight_smile:

2 Likes

I have created a macro using a combination of PyTime operations and shortcuts. It is meant to work with multiple clips selected. It works flawlessly with a single selection, but with multiple selections, the shortcuts only work on the initial selection, whereas the PyTime operations work correctly on all selected clips. This sort of thing is WAY out of my zone, so I don’t know enough to know if there is something wrong, or if the shortcuts only work on single selections. In fact, my first question would have been moot if I could have the shortcuts work with multiple selections. I could just use (“Go to Clip End”)

Can you share the relevant part of the code? I would assume, that if the shortcut (used manually) works for a selection of clips, it would do the same if called via python. If not, you could iterate over the selection and call the shortcut once for each item.

I will send it along when I get in this morning.

1 Like

So this is the script in question with the execute_shortcut. It is meant to jog forward n frames on multiple clips. I’ve used this basic setup which I gleaned from John Geehreng’s GoToFrame1 for other things and they work well on multiple clips, such as going to a particular timecode, or setting a mark at a particular time. My goal is to build an alternate shortcut for many timeline navigation commands that will work on multiple selections of clips. The trouble I’m having with the execute_shortcut is that it works properly on a single clip, but when I selected multiple clips it only works on the first clip, but it does it with a number if iterations equal to the amount of clips I have selected.

And while I’m at it, I find that many shortcuts have ('s built into them. Is there any way to either change them, or make python not interpret them as brackets?
Multi_JogForward.py (722 Bytes)

If you are moving “10 frames”, instead of using the execute_shortcut, you can use the following:

sequence.current_time = sequence.current_time.get_value() + 10

Yes, but the point is, I want the shortcuts to work. I have literally been waiting decades for this. I chose this particular example because it shows the iteration issue. All of the shortcuts are behaving the same way. I’m sure, with enough time and effort I could learn to write something that does what every shortcut does, but for someone like me, I just want a simple way of telling the application to do the commands that I understand well, so that 10 things I need to do every day to n clips can be done in couple of keystrokes.

Any insight, however, on executing short cuts with brackets built into the names?

The “execute_shortcut()” function is not the better “python way” of doing things. It was added as a “workaround” to enable users do things that have not been added to the Python API yet. Using existing API functions on a PyObject helps you making sure of what is happening and on which object it is applied. Using the execute_shortcut() function will yield the same result as if the shortcut was used inside the application; it doesn’t have extra attributes or behaviour because is it called in a script. For example, if the shortcut is something that works on a single clip inside the application, you may need to do a lot of extra stuff in your script have the shortcut applied to multiple clips. In this case you would need for sure to do:

flame.media_panel.selected_entries = [ sequence ]
and maybe
sequence.open_as_sequence()

to make sure that the clip also is the selected target. So in short, execute_shortcut should only be used as a last resort.

I’m not looking for “extra attributes.” The beauty of a macro is that it executes many keystrokes with a single one. What may seem like an inelegant solution to you means nothing to me if it is simple to create and does exactly what I want it to do and does it to exactly the clips I want to do it to, even if that means that if I want to advance 10 frames, I just tell it to advance one frame 10 times. I don’t really want to learn how to code in order to make this stuff work for me. I had better repeatability on a CMX3400 in 1985 than I do with a flame in 2021. With a simple macro I can potentially reduce an half hour of work or more into a single keystroke. All I really want is to build a template that I can insert keystrokes into and execute with a single keystroke on as many clips as I want. You know . . . like 1985.

I totally agree with Philippe, that execute_shortcut should only be used if there is no native way to do it via the python api, but I also get your point Tim for the most simple solution of your problem. I think you don’t need to become a full-blown python developer to automate the little things, but I think it helps to know some basics to make your everyday life easier. :slight_smile:

So let’s get back to your problem and break things down:
The problem with your current approach is, that the shortcut itself does only work on a single clip. Otherwise you wouldn’t need this script, right? Normally, if you iterate over a list (selection), you reference the current object to do something with it, like this:

for sequence in selection:
    do_something_on(sequence)

As Philippe pointed out, the execute_shortcut has no additional parameters to make it aware of this. The only parameter is the name of the shortcut, right? So the execute_shortcut relies on the current selection, like you would do manually with your mouse and keyboard. If you have 5 clips selected, you’re just pressing the shortcut 5 times, but your selection does not change. There are still 5 clips selected and therefore only the first is changed. Does this make sense?
So if you wanted to do it like this, you would need to take care of the current selection, like this:

# let's respect PEP8 for the function name
def multi_jog_forward(selection):
    import flame
    for sequence in selection:
    	# select only the sequence from the current loop
    	flame.media_panel.selected_entries = [ sequence ]
        flame.execute_shortcut ("<n> Frames Forward")
    # revert to the initial selection (important if you want to call this twice!)
    flame.media_panel.selected_entries = selection

Let me know, if this makes sense or if you have further questions! :slight_smile:

2 Likes

Thank you Claus. It makes a bit of sense, but I admit: I struggle with this.

So which bit is missing to make it completely clear? :slight_smile:

“. . . . but I think it helps to know some basics.”

Hehe, ok, got it. :smiley:
I think that might be a bit much for a single post … :slight_smile: