How can i play and stop stage with extension of kit

I want to develop a simulation data software based on kit. At present, what I want to achieve is to complete scene play, data collection and scene stop in the extension. How can I realize automatic batch collection of simulation data?

Hi,
you could register a timeline event listener and get play/stop events, then query the data you need during that time:

    def on_timeline_event(e):
        if e.type == int(omni.timeline.TimelineEventType.PLAY):

        if e.type == int(omni.timeline.TimelineEventType.PAUSE):

    timeline_events = omni.timeline.get_timeline_interface().get_timeline_event_stream()
    state.timeline_event_sub = timeline_events.create_subscription_to_pop(on_timeline_event)

You can create a subscription to Kit update:

def _on_update(self, e):
     pass

self._update_sub = omni.kit.app.get_app().get_update_event_stream().create_subscription_to_pop(self._on_update, name="my update")

Is this what you are looking for?
Regards,
Ales

Thank you very much for answering me. According to your idea, I have completed automatic playing、stopping the scene and saving RGB images through custom extension. But I have encountered a new problem. How can I save the mask of objects in the scene like RGB images?Some codes are as follows:
from omni.syntheticdata import helpers, sensors
import omni.syntheticdata._syntheticdata as sd
sd_interface = sd.acquire_syntheticdata_interface()
viewport=omni.kit.viewport.get_viewport_interface()
sensor=sensors.create_or_retrieve_sensor(viewport,sd.SensorType.InstanceSegmentation)
data = sd_interface.get_sensor_host_uint32_texture_array(sensor)

I want to get the mask of object of scene, but i failed.

@xiaohualiao0319 I would suggest you take a look at omniverse replicator

https://docs.omniverse.nvidia.com/prod_extensions/prod_extensions/ext_replicator.html

There are many tutorials on randomization and saving synthetic data.