How do you get the current frame number?

I tried this

frame = ui.Frame

And this is what it looks like:


All I am trying to do is display a label when I set keys in the UI.

frame = ui.Frame

label.text = "6 Keys Set at frame " + str(frame)

Other wise the message is the same every time the user clicks the button.


Hi @DataJuggler. That class is actually a ui container that we call a frame. You want to use omni.timeline to get the current frame number. Here are the API docs: omni.timeline — kit-sdk 105.0 documentation

I show here how to get the timeline interface and how to convert seconds to frame number:

Let me know if you have any other questions on this.

Thank you again.

I am just posting the solution here in case I forget or anyone else finds this topic:

import omni.timeline

# get a reference to the timeline
timeline = omni.timeline.get_timeline_interface()
# get the current time
time = timeline.get_current_time()

# get the frames per second
fps = timeline.get_time_codes_per_seconds()

# set the current frame
frame = time * fps

# display results  
label.text = "6 keys were wet at frame " + str(frame)


1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.