How to execute subsequent code after opening a file

How can I make this sentence ‘’_ Stage (F “{file_patht} / wqq-xiangcunxiaozhen01-25a. USD”) 'after the code for opening the scene file is executed, the subsequent code is executed. At present, the scene is opened after almost all the code is executed.

Hi @Not-Wind

A possible solution is to execute the code when the OPENED stage event is triggered

import omni.usd

# callback
def on_stage_event(event):
    if event.type == int(omni.usd.StageEventType.OPENED):
        stage = omni.usd.get_context().get_stage()
        prim_list = [prim.GetPath().pathString for prim in stage.TraverseAll()]

# subscription 
stage_event_sub = (omni.usd.get_context()
                   .create_subscription_to_pop(on_stage_event, name="subscription name"))
1 Like

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