Python Usage Examples#

Get Open File Addon Callback#

The get_open_file_addon_callback() function returns a callback that creates an activity progress UI addon for file opening operations. This addon displays real-time progress information during file loading.

Here’s a complete example showing how to integrate the activity UI addon into a custom stage loading workflow.

import asyncio
import omni.activity.ui
from omni.kit.widget.prompt import PromptManager
import omni.usd

class CustomStageLoader:
    def __init__(self):
        self._callback = []

    def _register_addons(self):
        """Register all available addons."""
        if len(self._callback)>0:
            return
        try:
            import omni.activity.ui
            self._callback = [omni.activity.ui.get_open_file_addon_callback()]
        except (ImportError, AttributeError):
            pass  # Activity UI not available

    async def load_stage_with_progress(self, stage_path: str):
        """Load a stage with activity progress visualization."""

        self._register_addons()
        # Show a waiting prompt with activity progress
        await omni.kit.app.get_app().next_update_async()
        await omni.kit.app.get_app().next_update_async()

        prompt = PromptManager.post_simple_prompt(
            "Loading Stage",
            f"Opening {stage_path}...",
            None,
            shortcut_keys=False,
            width=500,
            callback_addons=self._callback,
        )

        # Wait for UI to render
        await omni.kit.app.get_app().next_update_async()
        await omni.kit.app.get_app().next_update_async()

        try:
            # Perform the actual stage loading
            context = omni.usd.get_context()
            success = await context.open_stage_async(stage_path)
            return success
        finally:
            # Hide the prompt when done
            if prompt:
                prompt.hide()

# Usage
loader = CustomStageLoader()
asyncio.ensure_future(loader.load_stage_with_progress("/path/to/stage.usd"))