### Launch Application (Linux) Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md Launches the Kit application using the repo.sh script in a Linux environment. This command starts the application with the updated dependencies, including the Commands window. ```bash ./repo.sh launch ``` -------------------------------- ### Launch Application (Windows) Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md Launches the Kit application using the repo.bat script in a Windows environment. This command starts the application with the updated dependencies, including the Commands window. ```powershell .\repo.bat launch ``` -------------------------------- ### Extension Startup and Shutdown Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This snippet shows the basic structure of an Omniverse Kit extension, including the on_startup and on_shutdown methods. The on_startup method is called when the extension is enabled, and the on_shutdown method is called when the extension is disabled. It prints messages to the console to indicate when the extension is starting up and shutting down. ```python class MySpawn_primsExtExtension(omni.ext.IExt): # ext_id is current extension id. It can be used with extension manager to query additional information, like where # this extension is located on filesystem. def on_startup(self, ext_id): print("[my.spawn_prims.ext] my spawn_prims ext startup") def on_shutdown(self): print("[my.spawn_prims.ext] my spawn_prims ext shutdown") ``` -------------------------------- ### Extension Python Code Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This Python code represents the basic structure of an Omniverse Kit extension. It imports necessary modules and defines a public function. This code serves as a starting point for customizing the extension's functionality. ```python import omni.ext import omni.ui as ui # Functions and vars are available to other extension as usual in python: `example.python_ext.some_public_function(x)` def some_public_function(x: int): print("[my.spawn_prims.ext] some_public_function was called with x: ", x) return x ** x # Any class derived from `omni.ext.IExt` in top level module (defined in `python.modules` of `extension.toml`) will be # instantiated when extension gets enabled and `on_startup(ext_id)` will be called. Later when extension gets disabled ``` -------------------------------- ### Building the Application (Linux) Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/README.md This command builds the application using the repo.sh script on Linux. It compiles the code and packages the extension for deployment. ```bash ./repo.sh build ``` -------------------------------- ### Building the Application (Windows) Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/README.md This command builds the application using the repo.bat script on Windows. It compiles the code and packages the extension for deployment. ```powershell .\repo.bat build ``` -------------------------------- ### Extension Startup and UI Creation Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md Defines the `MySpawn_primsExtExtension` class, which inherits from `omni.ext.IExt`. The `on_startup` method is called when the extension is enabled. It creates a UI window with a button that, when clicked, executes a command to spawn a cube. ```python class MySpawn_primsExtExtension(omni.ext.IExt): # ext_id is current extension id. It can be used with extension manager to query additional information, like where # this extension is located on filesystem. def on_startup(self, ext_id): print("[my.spawn_prims.ext] my spawn_prims ext startup") self._window = ui.Window("Spawn Primitives", width=300, height=300) with self._window.frame: with ui.VStack(): def on_click(): omni.kit.commands.execute('CreateMeshPrimWithDefaultXform', prim_type='Cube', above_ground=True) with ui.HStack(): ui.Button("Spawn Cube", clicked_fn=on_click) ``` -------------------------------- ### Launching the Kit Application (Linux) Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This bash script launches the Kit application after it has been built. This allows you to test and use the newly added extension within the application environment. ```bash ./repo.sh launch ``` -------------------------------- ### Creating a New Extension Template (Linux) Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/README.md This command creates a new extension template using the repo.sh script on Linux. It initializes a basic extension structure that can be further customized. ```bash ./repo.sh template new ``` -------------------------------- ### Launching the Kit Application (Windows) Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This PowerShell script launches the Kit application after it has been built. This allows you to test and use the newly added extension within the application environment. ```powershell .\repo.bat launch ``` -------------------------------- ### Creating a New Extension Template (Windows) Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/README.md This command creates a new extension template using the repo.bat script on Windows. It initializes a basic extension structure that can be further customized. ```powershell .\repo.bat template new ``` -------------------------------- ### Complete Extension Code Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This snippet shows the complete code for the extension after making the changes described in the previous steps. It includes the necessary imports, the extension class, and the updated on_startup and on_shutdown methods. ```python import omni.ext import omni.ui as ui # Functions and vars are available to other extension as usual in python: `example.python_ext.some_public_function(x)` def some_public_function(x: int): print("[my.spawn_prims.ext] some_public_function was called with x: ", x) return x ** x # Any class derived from `omni.ext.IExt` in top level module (defined in `python.modules` of `extension.toml`) will be # instantiated when extension gets enabled and `on_startup(ext_id)` will be called. Later when extension gets disabled # on_shutdown() is called. class MySpawn_primsExtExtension(omni.ext.IExt): # ext_id is current extension id. It can be used with extension manager to query additional information, like where # this extension is located on filesystem. def on_startup(self, ext_id): print("[my.spawn_prims.ext] my spawn_prims ext startup") self._window = ui.Window("Spawn Primitives", width=300, height=300) with self._window.frame: with ui.VStack(): def on_click(): pass with ui.HStack(): ui.Button("Spawn Cube", clicked_fn=on_click) def on_shutdown(self): print("[my.spawn_prims.ext] my spawn_prims ext shutdown") ``` -------------------------------- ### Creating a New Extension (Linux) Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This bash script uses the repo.sh script to create a new extension from a template. This is the first step in building a custom extension for the Kit application. ```bash ./repo.sh template new ``` -------------------------------- ### Extension Startup with Cone Button Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md Modified `on_startup` method to include a second button for spawning a cone. Both buttons initially call the same `on_click` function, resulting in both spawning cubes. ```python def on_startup(self, ext_id): print("[omni.example.spawn_prims] MyExtension startup") self._window = ui.Window("Spawn Primitives", width=300, height=300) with self._window.frame: with ui.VStack(): def on_click(): omni.kit.commands.execute('CreateMeshPrimWithDefaultXform', prim_type='Cube', above_ground=True) ui.Button("Spawn Cube", clicked_fn=on_click) ui.Button("Spawn Cone", clicked_fn=on_click) ``` -------------------------------- ### Building the Kit Application (Linux) Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This bash script rebuilds the Kit application after a new extension has been added to the .kit file. This ensures that the extension is properly integrated into the application's build directory. ```bash ./repo.sh build ``` -------------------------------- ### Creating a New Extension (Windows) Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This PowerShell script uses the repo.bat script to create a new extension from a template. This is the first step in building a custom extension for the Kit application. ```powershell .\repo.bat template new ``` -------------------------------- ### Building the Kit Application (Windows) Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This PowerShell script rebuilds the Kit application after a new extension has been added to the .kit file. This ensures that the extension is properly integrated into the application's build directory. ```powershell .\repo.bat build ``` -------------------------------- ### Spawning Cube and Cone Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md Modified `on_click` function to spawn both a cube and a cone. This demonstrates how to execute multiple commands sequentially. ```python def on_click(): #Create a Cube omni.kit.commands.execute('CreateMeshPrimWithDefaultXform', prim_type='Cube', above_ground=True) #Create a Cone omni.kit.commands.execute('CreateMeshPrimWithDefaultXform', prim_type='Cone', above_ground=True) ``` -------------------------------- ### Initializing UI Window Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This snippet initializes a UI window using the omni.ui module. It creates a window with a specified title, width, and height. It also sets up a vertical stack layout within the window's frame. ```python self._window = ui.Window("My Window", width=300, height=300) with self._window.frame: with ui.VStack(): label = ui.Label("") ``` -------------------------------- ### Add Commands Window Dependency Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md Adds the omni.kit.window.commands extension as a dependency in the .kit file to enable the Commands window in the Kit application. This allows users to view and interact with executed commands. ```json "omni.kit.window.commands" = {} # Commands Extension Window ``` -------------------------------- ### Review and Save Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This Python code snippet shows the import statements required for an Omniverse Kit extension that uses UI elements and commands. It imports `omni.ext`, `omni.ui`, and `omni.kit.commands`. ```python import omni.ext import omni.ui as ui import omni.kit.commands ``` -------------------------------- ### Adding Extension Dependency to Kit Application Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This JSON snippet shows how to add a dependency to the .kit file, which is necessary for the application to recognize and load the new extension. The extension is added to the dependencies section of the .kit file. ```json "my.spawn_prims.ext" = {} ``` -------------------------------- ### Relocate Create Command Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This Python code snippet defines a function `on_click` that executes a command to create a cube primitive with default transformations. It uses the `omni.kit.commands.execute` function to trigger the 'CreateMeshPrimWithDefaultXform' command, specifying the primitive type as 'Cube' and setting the `above_ground` parameter to True. ```python def on_click(): omni.kit.commands.execute('CreateMeshPrimWithDefaultXform', prim_type='Cube', above_ground=True) ``` -------------------------------- ### Passing Prim Type to on_click() Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md Updated the `clicked_fn` for both UI Buttons to pass the desired `prim_type` (either "Cube" or "Cone") to the `on_click` function. ```python ui.Button("Spawn Cube", clicked_fn=on_click("Cube")) ui.Button("Spawn Cone", clicked_fn=on_click("Cone")) ``` -------------------------------- ### Spawn Cube Command in Extension Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This Python code snippet demonstrates how to create a cube within an Omniverse Kit extension using the `omni.kit.commands.execute` function. It defines an `on_click` function that, when triggered, executes the 'CreateMeshPrimWithDefaultXform' command to spawn a cube with specified properties. ```python import omni.ext import omni.ui as ui # Functions and vars are available to other extension as usual in python: `example.python_ext.some_public_function(x)` def some_public_function(x: int): print("[my.spawn_prims.ext] some_public_function was called with x: ", x) return x ** x # Any class derived from `omni.ext.IExt` in top level module (defined in `python.modules` of `extension.toml`) will be # instantiated when extension gets enabled and `on_startup(ext_id)` will be called. Later when extension gets disabled # on_shutdown() is called. class MySpawn_primsExtExtension(omni.ext.IExt): # ext_id is current extension id. It can be used with extension manager to query additional information, like where # this extension is located on filesystem. def on_startup(self, ext_id): print("[my.spawn_prims.ext] my spawn_prims ext startup") self._window = ui.Window("Spawn Primitives", width=300, height=300) with self._window.frame: with ui.VStack(): def on_click(): import omni.kit.commands omni.kit.commands.execute('CreateMeshPrimWithDefaultXform', prim_type='Cube', above_ground=True) with ui.HStack(): ui.Button("Spawn Cube", clicked_fn=on_click) def on_shutdown(self): print("[my.spawn_prims.ext] my spawn_prims ext shutdown") ``` -------------------------------- ### Accepting Prim Type in on_click() Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md Modified `on_click` function to accept a `prim_type` argument, allowing it to be used for spawning different primitive types. ```python def on_click(prim_type): ``` -------------------------------- ### Declaring Extension Dependency in .kit file Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/README.md This TOML snippet declares a dependency on the 'omni.example.spawn_prims' extension within the application's .kit file. This ensures that the extension is loaded and available for use by the application. ```toml [dependencies] "omni.example.spawn_prims" = {} ``` -------------------------------- ### Using Prim Type in on_click() Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md Modified `on_click` function to use the `prim_type` argument when executing the `CreateMeshPrimWithDefaultXform` command. ```python def on_click(prim_type): omni.kit.commands.execute('CreateMeshPrimWithDefaultXform', prim_type=prim_type, above_ground=True) ``` -------------------------------- ### Spawning Primitives Extension Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This extension creates a UI with buttons to spawn different primitive types (Cube, Cone, Cylinder, Disk, Plane, Sphere, Torus) in the Omniverse environment. It uses the omni.ui module for UI creation and omni.kit.commands to execute the mesh creation commands. The on_click function takes a prim_type argument to determine which mesh to create. ```Python import omni.ext import omni.ui as ui import omni.kit.commands # Functions and vars are available to other extension as usual in python: `example.python_ext some_public_function(x)` def some_public_function(x: int): print("[my.spawn_prims.ext] some_public_function was called with x: ", x) return x ** x # Any class derived from `omni.ext.IExt` in top level module (defined in `python.modules` of `extension.toml`) will be # instantiated when extension gets enabled and `on_startup(ext_id)` will be called. Later when extension gets disabled # on_shutdown() is called. class MyExtension(omni.ext.IExt): # ext_id is current extension id. It can be used with extension manager to query additional information, like where # this extension is located on filesystem. def on_startup(self, ext_id): print("[omni.example.spawn_prims] MyExtension startup") self._window = ui.Window("Spawn Primitives", width=300, height=300) with self._window.frame: with ui.VStack(): def on_click(prim_type): omni.kit.commands.execute('CreateMeshPrimWithDefaultXform', prim_type=prim_type, above_ground=True) ui.Button("Spawn Cube", clicked_fn=on_click("Cube")) ui.Button("Spawn Cone", clicked_fn=on_click("Cone")) ui.Button("Spawn Cylinder", clicked_fn=on_click("Cylinder")) ui.Button("Spawn Disk", clicked_fn=on_click("Disk")) ui.Button("Spawn Plane", clicked_fn=on_click("Plane")) ui.Button("Spawn Sphere", clicked_fn=on_click("Sphere")) ui.Button("Spawn Torus", clicked_fn=on_click("Torus")) def on_shutdown(self): print("[omni.example.spawn_prims] MyExtension shutdown") ``` -------------------------------- ### Group Imports Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This Python code snippet shows how to group import statements at the top of a module for better code organization and readability. It imports necessary modules for creating extensions, user interfaces, and executing commands within the Omniverse Kit environment. ```python import omni.ext import omni.ui as ui import omni.kit.commands ``` -------------------------------- ### Public Function Definition Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md Defines a public function `some_public_function` that can be accessed by other extensions. It takes an integer as input, prints a message, and returns the input raised to the power of itself. ```python def some_public_function(x: int): print("[my.spawn_prims.ext] some_public_function was called with x: ", x) return x ** x ``` -------------------------------- ### Defining Button Click Action Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This snippet defines a function that is called when a button is clicked. It increments a counter and updates the text of a label to display the current count. It also defines a reset function to set the counter to zero. ```python def on_click(): self._count += 1 label.text = f"count: {self._count}" def on_reset(): self._count = 0 label.text = "empty" on_reset() with ui.HStack(): ui.Button("Add", clicked_fn=on_click) ui.Button("Reset", clicked_fn=on_reset) ``` -------------------------------- ### Updating Window Title Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This snippet updates the title of the UI window to "Spawn Primitives". This change provides a more descriptive title for the window, reflecting its purpose within the extension. ```python self._window = ui.Window("Spawn Primitives", width=300, height=300) ``` -------------------------------- ### Extension Shutdown Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md Defines the `on_shutdown` method, which is called when the extension is disabled. It prints a message to the console. ```python def on_shutdown(self): print("[my.spawn_prims.ext] my spawn_prims ext shutdown") ``` -------------------------------- ### Updating Button Text Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This snippet updates the text of the button to "Spawn Cube". This change reflects the button's new functionality of spawning a cube primitive. ```python ui.Button("Spawn Cube", clicked_fn=on_click) ``` -------------------------------- ### Removing Label and Reset Functionality Source: https://github.com/nvidia-omniverse/kit-extension-sample-spawn-prims/blob/main/exts/omni.example.spawn_prims/tutorial/tutorial.md This snippet removes the label and reset functionality from the extension. The label and reset button are no longer needed for the intended purpose of spawning primitives. The on_click function is replaced with a pass statement. ```python def on_startup(self, ext_id): print("[my.spawn_prims.ext] my spawn_prims ext startup") self._window = ui.Window("Spawn Primitives", width=300, height=300) with self._window.frame: with ui.VStack(): def on_click(): pass with ui.HStack(): ui.Button("Add", clicked_fn=on_click) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.