file_path
stringlengths
21
224
content
stringlengths
0
80.8M
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_08/docs/README.md
# Developer Office Hour - 09/08/2023 This is the sample code from the Developer Office Hour held on 09/08/2023, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - 2:22 - How do I listen for or subscribe to an event in Omniverse Kit? - 15:14 - How do I run a function every N seconds during playback? - 44:00 - How do I link to a DLL with an extension?
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_21/maticodes/doh_2022_10_21/extension.py
# SPDX-License-Identifier: Apache-2.0 import carb import omni.ext import omni.ui as ui class MyCoolComponent: def __init__(self): with ui.HStack(): ui.Label("My Field") ui.StringField() class MyWindow(ui.Window): def __init__(self, title: str = None, **kwargs): super().__init__(title, **kwargs) self.frame.set_build_fn(self._build_window) def _build_window(self): with ui.ScrollingFrame(): with ui.VStack(height=0): ui.Label("My Label") self.build_field_with_label() MyCoolComponent() def clicked(): carb.log_info("Button Clicked!") ui.Button("Click Me", clicked_fn=clicked) def build_field_with_label(self): with ui.HStack(): ui.Label("My Field") ui.StringField() class MyExtension(omni.ext.IExt): def on_startup(self, ext_id): carb.log_info("[maticodes.doh_2022_10_21] Dev Office Hours Extension (2022-10-21) startup") self._window = MyWindow("MyWindow", width=300, height=300) def on_shutdown(self): carb.log_info("[maticodes.doh_2022_10_21] Dev Office Hours Extension (2022-10-21) shutdown") if self._window: self._window.destroy() self._window = None
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_21/maticodes/doh_2022_10_21/__init__.py
# SPDX-License-Identifier: Apache-2.0 from .extension import *
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_21/scripts/my_script.py
# SPDX-License-Identifier: Apache-2.0
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_21/config/extension.toml
[package] # Semantic Versionning is used: https://semver.org/ version = "1.0.0" # The title and description fields are primarily for displaying extension info in UI title = "2022-10-21: Dev Office Hours" description="Sample code from the Dev Office Hour held on 2022-10-21" # Path (relative to the root) or content of readme markdown file for UI. readme = "docs/README.md" # URL of the extension source repository. repository = "" # One of categories for UI. category = "Example" # Keywords for the extension keywords = ["kit", "example"] # Use omni.ui to build simple UI [dependencies] "omni.kit.uiapp" = {} # Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_10_21". [[python.module]] name = "maticodes.doh_2022_10_21"
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_21/docs/README.md
# Developer Office Hour - 10/21/2022 This is the sample code from the Developer Office Hour held on 10/21/2022, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions 1. Where are Omniverse logs located? 2. Where is the data directory for an Omniverse app? 3. What is link_app.bat? 4. How do I get intellisense working in VS Code?
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_30/maticodes/doh_2022_09_30/extension.py
# SPDX-License-Identifier: Apache-2.0 import carb import omni.ext import omni.ui as ui class MyWindow(ui.Window): def __init__(self, title: str = None, **kwargs): super().__init__(title, **kwargs) self.frame.set_build_fn(self._build_window) def _build_window(self): with ui.ScrollingFrame(): with ui.VStack(height=0): ui.Label("My Label") def clicked(): carb.log_info("Button Clicked!") ui.Button("Click Me", clicked_fn=clicked) class MyExtension(omni.ext.IExt): def on_startup(self, ext_id): carb.log_info("[maticodes.doh_2022_09_30] Dev Office Hours Extension (2022-09-30) startup") self._window = MyWindow("MyWindow", width=300, height=300) def on_shutdown(self): carb.log_info("[maticodes.doh_2022_09_30] Dev Office Hours Extension (2022-09-30) shutdown") if self._window: self._window.destroy() self._window = None
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_30/maticodes/doh_2022_09_30/__init__.py
# SPDX-License-Identifier: Apache-2.0 from .extension import *
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_30/scripts/curve_widths.py
# SPDX-License-Identifier: Apache-2.0 import omni.usd from pxr import UsdGeom stage = omni.usd.get_context().get_stage() prim = stage.GetPrimAtPath("/World/BasisCurves") prim.GetAttribute("widths").Set([5, 10,5, 10,5, 10,5, 10,5, 10,5, 10,5]) curves: UsdGeom.BasisCurves = UsdGeom.BasisCurves(prim) print(curves.GetWidthsInterpolation())
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_30/scripts/omnigraph.py
""" https://docs.omniverse.nvidia.com/py/kit/source/extensions/omni.graph/docs/index.html https://docs.omniverse.nvidia.com/py/kit/source/extensions/omni.graph/docs/controller.html#howto-omnigraph-controller """ import omni.graph.core as og controller: og.Controller = og.Controller() keys = og.Controller.Keys # Create an Action Graph # SPDX-License-Identifier: Apache-2.0 graph = controller.create_graph({ "graph_path": "/World/CameraAim", "evaluator_name": "execution" # This makes it Action Graph }) # Create some nodes _, nodes, _, _ = controller.edit(graph, {keys.CREATE_NODES: ("OnTick", "omni.graph.action.OnTick")}) on_tick = nodes[0] _, nodes, _, _ = controller.edit(graph, {keys.CREATE_NODES: ("SetCameraTarget", "omni.graph.ui.SetCameraTarget")}) set_cam_target = nodes[0] # Edit an attribute # /World/CameraAim/OnTick.inputs:onlyPlayback controller.edit(graph, {keys.SET_VALUES: (on_tick.get_attribute("inputs:onlyPlayback"), False)}) # Connect two attributes controller.connect(on_tick.get_attribute("outputs:tick"), set_cam_target.get_attribute("inputs:execIn"))
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_30/scripts/vp2.py
# SPDX-License-Identifier: Apache-2.0 # DON'T DO THIS ANYMORE import omni.kit.viewport_legacy viewport_interface = omni.kit.viewport_legacy.acquire_viewport_interface() vp_win = viewport_interface.get_viewport_window() print(vp_win) # DO THIS import omni.kit.viewport.utility as vp_util vp_win = vp_util.get_active_viewport_window() print(vp_win)
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_30/scripts/docking.py
# SPDX-License-Identifier: Apache-2.0 import omni.ui as ui my_window = ui.Window("Example Window", width=300, height=300) with my_window.frame: with ui.VStack(): f = ui.FloatField() def clicked(f=f): print("clicked") f.model.set_value(f.model.get_value_as_float() + 1) ui.Button("Plus One", clicked_fn=clicked) my_window.dock_in_window("Property", ui.DockPosition.SAME) ui.dock_window_in_window(my_window.title, "Property", ui.DockPosition.RIGHT, 0.1) my_window.deferred_dock_in("Content", ui.DockPolicy.CURRENT_WINDOW_IS_ACTIVE)
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_30/config/extension.toml
[package] # Semantic Versionning is used: https://semver.org/ version = "1.0.0" # The title and description fields are primarily for displaying extension info in UI title = "2022-09-30: Dev Office Hours" description="Sample code from the Dev Office Hour held on 2022-09-30" # Path (relative to the root) or content of readme markdown file for UI. readme = "docs/README.md" # URL of the extension source repository. repository = "" # One of categories for UI. category = "Example" # Keywords for the extension keywords = ["kit", "example"] # Use omni.ui to build simple UI [dependencies] "omni.kit.uiapp" = {} # Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_09_30". [[python.module]] name = "maticodes.doh_2022_09_30"
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_30/docs/README.md
# Developer Office Hour - 09/30/2022 This is the sample code from the Developer Office Hour held on 09/30/2022, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - Why is the legacy viewport API not working anymore? - How do I create an OmniGraph using Python scripting?
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_04/maticodes/doh_2022_11_04/extension.py
# SPDX-License-Identifier: Apache-2.0 from pathlib import Path import carb import numpy as np import omni.ext import omni.kit.app import omni.ui as ui from PIL import Image class MyWindow(ui.Window): def __init__(self, ext_path, title: str = None, **kwargs): super().__init__(title, **kwargs) data_dir = Path(ext_path) / "data" files = list(data_dir.glob("*")) self.images = [] for f in files: with Image.open(f) as img: np_data = np.asarray(img).data data = img.getdata() self.images.append((np_data, data, img.size)) self.provider = ui.ByteImageProvider() if hasattr(self.provider, "set_data_array"): self.provider.set_data_array(self.images[0][0], self.images[0][2]) else: self.provider.set_bytes_data(self.images[0][1], self.images[0][2]) self.frame.set_build_fn(self._build_window) def _build_window(self): with ui.ScrollingFrame(): with ui.VStack(height=0): ui.ImageWithProvider(self.provider, width=100, height=100) def clicked(): img = self.images.pop() self.images.insert(0, img) if hasattr(self.provider, "set_data_array"): self.provider.set_data_array(img[0], img[2]) else: self.provider.set_bytes_data(img[1], img[2]) ui.Button("Click Me", clicked_fn=clicked) class MyExtension(omni.ext.IExt): def on_startup(self, ext_id): carb.log_info("[maticodes.doh_2022_11_04] Dev Office Hours Extension (2022-11-04) startup") manager = omni.kit.app.get_app().get_extension_manager() ext_path = manager.get_extension_path(ext_id) self._window = MyWindow(ext_path, "MyWindow", width=300, height=300) def on_shutdown(self): carb.log_info("[maticodes.doh_2022_11_04] Dev Office Hours Extension (2022-11-04) shutdown") if self._window: self._window.destroy() self._window = None
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_04/maticodes/doh_2022_11_04/__init__.py
# SPDX-License-Identifier: Apache-2.0 from .extension import *
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_04/scripts/progress_bar.py
# SPDX-License-Identifier: Apache-2.0 import omni.ui as ui style = { "color": ui.color.red, "background_color": ui.color.blue, "secondary_color": ui.color.white, } class CustomProgressValueModel(ui.AbstractValueModel): """An example of custom float model that can be used for progress bar""" def __init__(self, value: float): super().__init__() self._value = value def set_value(self, value): """Reimplemented set""" try: value = float(value) except ValueError: value = None if value != self._value: # Tell the widget that the model is changed self._value = value self._value_changed() def get_value_as_float(self): return self._value def get_value_as_string(self): return f"{self._value*100:.0f}%" my_window = ui.Window("Example Window", width=300, height=300) with my_window.frame: with ui.VStack(): model = CustomProgressValueModel(0.0) pb = ui.ProgressBar(model, style=style, height=0) # pb = ui.ProgressBar(style=style, height=0) def clicked(): print("clicked") value = pb.model.as_float pb.model.set_value(value + 0.1) ui.Button("Plus One", clicked_fn=clicked)
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_04/scripts/loop.py
# SPDX-License-Identifier: Apache-2.0 my_list = [1,2,3] s = set([1,2,3]) d = {"one": 1, "two": 2} t = (1,2,3) # range, enumerate, filter, map, zip # https://docs.python.org/3.7/library/functions.html # Topics to research: Iterable, iterator, generator from pxr import Vt, Gf for i, x in enumerate(my_list): print(i, x) for x in Gf.Vec3f([1,2,3]): print(x) my_usd_arr = Vt.BoolArray([False, True, False]) print(type(my_usd_arr)) for x in my_usd_arr: print(x) for i, x in Vt.BoolArray([False, True, False]): print(i, x) class PowTwo: num = 1 def __iter__(self): return self def __next__(self): self.num = self.num * 2 if self.num > 32: raise StopIteration() return self.num pow2 = PowTwo() # for x in pow2: # print(x) print(next(pow2)) print(next(pow2)) print(next(pow2)) print(next(pow2)) print(next(pow2)) print(next(pow2)) print(next(pow2))
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_04/scripts/ext_names.txt
Extension Naming Recommendations - my_name.my_pkg.etc - my_name should be unique to you or your org - my_name should not be omni funkyboy.asset maticodes.asset NOT stephen.asset My Recommendations: - Follow PEP 423 - try short names, but if you need compound names then use underscore - maticodes.my_asset - all lower case
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_04/config/extension.toml
[package] # Semantic Versionning is used: https://semver.org/ version = "1.0.0" # The title and description fields are primarily for displaying extension info in UI title = "2022-11-04: Dev Office Hours" description="Sample code from the Dev Office Hour held on 2022-11-04" # Path (relative to the root) or content of readme markdown file for UI. readme = "docs/README.md" # URL of the extension source repository. repository = "" # One of categories for UI. category = "Example" # Keywords for the extension keywords = ["kit", "example"] # Use omni.ui to build simple UI [dependencies] "omni.kit.uiapp" = {} # Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_11_04". [[python.module]] name = "maticodes.doh_2022_11_04"
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_04/docs/README.md
# Developer Office Hour - 11/04/2022 This is the sample code from the Developer Office Hour held on 11/04/2022, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - How can I display dynamic images within a frame? - What can I use a for loop with? - How do I create a progress bar?
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_12/maticodes/doh_2023_05_12/extension.py
# SPDX-License-Identifier: Apache-2.0 import carb import omni.ext import omni.ui as ui class MyWindow(ui.Window): def __init__(self, title: str = None, **kwargs): super().__init__(title, **kwargs) self.frame.set_build_fn(self._build_window) def _build_window(self): with ui.ScrollingFrame(): with ui.VStack(height=0): ui.Label("My Label") def clicked(): carb.log_info("Button Clicked!") ui.Button("Click Me", clicked_fn=clicked) class MyExtension(omni.ext.IExt): def on_startup(self, ext_id): carb.log_info("[maticodes.doh_2023_05_12] Dev Office Hours Extension (2023-05-12) startup") self._window = MyWindow("MyWindow", width=300, height=300) def on_shutdown(self): carb.log_info("[maticodes.doh_2023_05_12] Dev Office Hours Extension (2023-05-12) shutdown") if self._window: self._window.destroy() self._window = None
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_12/maticodes/doh_2023_05_12/__init__.py
# SPDX-License-Identifier: Apache-2.0 from .extension import *
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_12/scripts/my_script.py
# SPDX-License-Identifier: Apache-2.0 import omni.ui as ui
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_12/config/extension.toml
[package] # Semantic Versionning is used: https://semver.org/ version = "1.0.0" # The title and description fields are primarily for displaying extension info in UI title = "2023-05-12: Dev Office Hours" description="Sample code from the Dev Office Hour held on 2023-05-12" # Path (relative to the root) or content of readme markdown file for UI. readme = "docs/README.md" # URL of the extension source repository. repository = "" # One of categories for UI. category = "Example" # Keywords for the extension keywords = ["kit", "example"] # Use omni.ui to build simple UI [dependencies] "omni.kit.uiapp" = {} # Main python module this extension provides, it will be publicly available as "import maticodes.doh_2023_05_12". [[python.module]] name = "maticodes.doh_2023_05_12"
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_12/docs/README.md
# Developer Office Hour - 05/12/2023 This is the sample code from the Developer Office Hour held on 05/12/2023, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - 02:30 - How do you add two windows from one extension?
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_20/maticodes/doh_2023_01_20/extension.py
# SPDX-License-Identifier: Apache-2.0 import carb import omni.ext import omni.ui as ui class MyWindow(ui.Window): def __init__(self, title: str = None, **kwargs): super().__init__(title, **kwargs) self.frame.set_build_fn(self._build_window) def _build_window(self): with ui.ScrollingFrame(): with ui.VStack(height=0): ui.Label("My Label") def clicked(): carb.log_info("Button Clicked!") ui.Button("Click Me", clicked_fn=clicked) class MyExtension(omni.ext.IExt): def on_startup(self, ext_id): carb.log_info("[maticodes.doh_2023_01_20] Dev Office Hours Extension (2023-01-20) startup") self._window = MyWindow("MyWindow", width=300, height=300) def on_shutdown(self): carb.log_info("[maticodes.doh_2023_01_20] Dev Office Hours Extension (2023-01-20) shutdown") if self._window: self._window.destroy() self._window = None
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_20/maticodes/doh_2023_01_20/__init__.py
# SPDX-License-Identifier: Apache-2.0 from .extension import *
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_20/scripts/check_omni_file_exists.py
# SPDX-License-Identifier: Apache-2.0 import omni.client result, list_entry = omni.client.stat("omniverse://localhost/Users/test/helloworld_py.usd") if result == omni.client.Result.OK: # Do things print(list_entry) # When a file doesn't exist, the result is omni.client.Result.ERROR_NOT_FOUND result, list_entry = omni.client.stat("omniverse://localhost/Users/test/fake.usd") print(result, list_entry)
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_20/scripts/duplicate_prim.py
# SPDX-License-Identifier: Apache-2.0 # paths_to import omni.kit.commands result = omni.kit.commands.execute('CopyPrims', paths_from=['/World/Cube'], paths_to=["/World/MyCopiedCube"], duplicate_layers=False, combine_layers=False, flatten_references=False) print(result)
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_20/scripts/selection_changed_event.py
# SPDX-License-Identifier: Apache-2.0 import carb import omni.usd usd_ctx = omni.usd.get_context() def on_selection_changed(event: carb.events.IEvent): print("Selection Changed") # https://docs.omniverse.nvidia.com/prod_kit/prod_kit/python-snippets/selection/get-current-selected-prims.html selection = usd_ctx.get_selection().get_selected_prim_paths() print(f"New selection: {selection}") sel_sub = usd_ctx.get_stage_event_stream().create_subscription_to_pop_by_type(omni.usd.StageEventType.SELECTION_CHANGED, on_selection_changed) # Don't forget to unsubscribe when you're done with it or when your extension shuts down. sel_sub.unsubscribe()
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_20/config/extension.toml
[package] # Semantic Versionning is used: https://semver.org/ version = "1.0.0" # The title and description fields are primarily for displaying extension info in UI title = "2023-01-20: Dev Office Hours" description="Sample code from the Dev Office Hour held on 2023-01-20" # Path (relative to the root) or content of readme markdown file for UI. readme = "docs/README.md" # URL of the extension source repository. repository = "" # One of categories for UI. category = "Example" # Keywords for the extension keywords = ["kit", "example"] # Use omni.ui to build simple UI [dependencies] "omni.kit.uiapp" = {} # Main python module this extension provides, it will be publicly available as "import maticodes.doh_2023_01_20". [[python.module]] name = "maticodes.doh_2023_01_20"
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_20/docs/README.md
# Developer Office Hour - 01/20/2023 This is the sample code from the Developer Office Hour held on 01/20/2023, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - 3:57 - How do I check if a file exists using the Omni Client Library? - 6:51 - How do I duplicate a prim? - 13:53 - Is there an event for when a user's prim selection changes?
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/maticodes/doh_2022_09_02/extension.py
# SPDX-License-Identifier: Apache-2.0 import carb import omni.ext import omni.ui as ui class MyWindow(ui.Window): def __init__(self, title: str = None, **kwargs): super().__init__(title, **kwargs) self.frame.set_build_fn(self._build_window) def _build_window(self): with ui.ScrollingFrame(): with ui.VStack(height=0): ui.Label("My Label") def clicked(): carb.log_info("Button Clicked!") ui.Button("Click Me", clicked_fn=clicked) class MyExtension(omni.ext.IExt): def on_startup(self, ext_id): carb.log_info("[maticodes.doh_2022_09_02] Dev Office Hours Extension (2022-09-02) startup") self._window = MyWindow("MyWindow", width=300, height=300) def on_shutdown(self): carb.log_info("[maticodes.doh_2022_09_02] Dev Office Hours Extension (2022-09-02) shutdown") if self._window: self._window.destroy() self._window = None
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/maticodes/doh_2022_09_02/__init__.py
# SPDX-License-Identifier: Apache-2.0 from .extension import *
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/scripts/what_is_sc.py
# SPDX-License-Identifier: Apache-2.0 from omni.ui import scene as sc
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/scripts/get_local.py
# SPDX-License-Identifier: Apache-2.0 import omni.usd from pxr import Usd, Gf stage = omni.usd.get_context().get_stage() prim = stage.GetPrimAtPath("/World/Cube_01") scale, rotate, rot_order, translate = omni.usd.get_local_transform_SRT(prim, time=Usd.TimeCode.Default()) print(scale, rotate, rot_order, translate) # Gf.Vec3d # (Double, Double, Double) # Gf.Matrix4d # (Double, Double, Double, Double) # (Double, Double, Double, Double) # (Double, Double, Double, Double) # (Double, Double, Double, Double) matrix:Gf.Matrix4d = omni.usd.get_local_transform_matrix(prim, time_code=Usd.TimeCode.Default()) print(matrix)
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/scripts/define_ui_colors.py
# SPDX-License-Identifier: Apache-2.0 import omni.ui as ui from omni.ui import color as cl my_window = ui.Window("Example Window", width=300, height=300) with my_window.frame: with ui.VStack(): ui.Label("AABBGGRR", style={"color": 0xFF00FFFF}) # STAY AWAY FROM ui.Label("Float RGB", style={"color": cl(1.0, 1.0, 0.0)}) ui.Label("Float RGBA", style={"color": cl(1.0, 1.0, 0.0, 0.5)}) ui.Label("Int RGB", style={"color": cl(255, 255, 0)}) ui.Label("Int RGBA", style={"color": cl(255, 255, 0, 128)}) ui.Label("Oops RGB", style={"color": cl(1, 1, 0)}) ui.Label("Web Hex RGB", style={"color": cl("#FFFF00")}) ui.Label("Web Hex rgb", style={"color": cl("#ffff00")}) ui.Label("Web Hex RGBA", style={"color": cl("#FFFF0088")}) ui.Label("Float RGB White", style={"color": cl(1.0, 1.0, 1.0)}) ui.Label("Float RGB 50%", style={"color": cl(0.5, 0.5, 0.5)}) ui.Label("Float Greyscale White", style={"color": cl(1.0)}) ui.Label("Float Greyscale 50%", style={"color": cl(0.5)}) ui.Label("Int Greyscale White", style={"color": cl(255)}) ui.Label("Int Greyscale 50%", style={"color": cl(128)}) ui.Label("Web Color Name", style={"color": cl.yellow})
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/scripts/add_menu.py
# SPDX-License-Identifier: Apache-2.0 import omni.kit.ui menu_path = "File/Foo" menu_path2 = "File/Foo/Bar" def on_menu_click(menu_path, toggled): print(menu_path) print(toggled) menu = omni.kit.ui.get_editor_menu().add_item(menu_path, on_menu_click) menu = omni.kit.ui.get_editor_menu().add_item(menu_path2, on_menu_click, True) omni.kit.ui.get_editor_menu().remove_item(menu) import omni.kit.menu.utils from omni.kit.menu.utils import MenuItemDescription menu_item = MenuItemDescription( name="Hello World!", glyph="save.svg", onclick_fn=lambda: print("Hello World!"), # hotkey=( # carb.input.KEYBOARD_MODIFIER_FLAG_CONTROL | carb.input.KEYBOARD_MODIFIER_FLAG_ALT, # carb.input.KeyboardInput.S, #), ) menus = [menu_item] omni.kit.menu.utils.add_menu_items([menu_item], "File") omni.kit.menu.utils.remove_menu_items([menu_item], "File", rebuild_menus=True) # omni.kit.ui.get_editor_menu().convert_to_new_menu
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/scripts/what_is_cl.py
# SPDX-License-Identifier: Apache-2.0 import omni.ui as ui from omni.ui import color as cl # import omni.ui.color as color my_window = ui.Window("Example Window", width=300, height=300) with my_window.frame: with ui.VStack(): ui.Label("Hello World!", style={"color": cl(0.0, 1.0, 0.0)})
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/config/extension.toml
[package] # Semantic Versionning is used: https://semver.org/ version = "1.0.0" # The title and description fields are primarily for displaying extension info in UI title = "2022-09-02: Dev Office Hours" description="Sample code from the Dev Office Hour held on 2022-09-02" # Path (relative to the root) or content of readme markdown file for UI. readme = "docs/README.md" # URL of the extension source repository. repository = "" # One of categories for UI. category = "Example" # Keywords for the extension keywords = ["kit", "example"] # Use omni.ui to build simple UI [dependencies] "omni.kit.uiapp" = {} # Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_09_02". [[python.module]] name = "maticodes.doh_2022_09_02"
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/docs/README.md
# Developer Office Hour - 09/02/2022 This is the sample code from the Developer Office Hour held on 09/02/2022, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - What's the difference between a shape and a mesh? - How do I import cl? - How do I import sc? - How do I define UI colors? - How do I add an item to a menu?
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_18/maticodes/doh_2022_11_18/extension.py
# SPDX-License-Identifier: Apache-2.0 import carb import omni.ext from omni.kit.viewport.utility import get_active_viewport_window import omni.ui as ui class MyExtension(omni.ext.IExt): def on_startup(self, ext_id): carb.log_info("[maticodes.doh_2022_11_18] Dev Office Hours Extension (2022-11-18) startup") self.custom_frame = None viewport_window = get_active_viewport_window() if viewport_window is not None: self.custom_frame: ui.Frame = viewport_window.get_frame(ext_id) with self.custom_frame: with ui.VStack(): ui.Spacer() with ui.HStack(height=0): ui.Spacer() ui.Button("Hello", width=0, height=0) def on_shutdown(self): carb.log_info("[maticodes.doh_2022_11_18] Dev Office Hours Extension (2022-11-18) shutdown") self.custom_frame.destroy() self.custom_frame = None
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_18/maticodes/doh_2022_11_18/__init__.py
# SPDX-License-Identifier: Apache-2.0 from .extension import *
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_18/scripts/placer_model.py
# SPDX-License-Identifier: Apache-2.0 import omni.ui as ui my_window = ui.Window("Example Window", width=300, height=300) model = ui.SimpleFloatModel() sub = None with my_window.frame: with ui.VStack(): ui.FloatSlider(model=model) def body_moved(body, model): if body.offset_x.value > 100: body.offset_x.value = 100 elif body.offset_x.value < 0: body.offset_x.value = 0 model.set_value(body.offset_x.value / 100.0) body = ui.Placer(draggable=True, drag_axis=ui.Axis.X, offset_x=0) with body: rect = ui.Rectangle(width=25, height=25, style={"background_color": ui.color.red}) body.set_offset_x_changed_fn(lambda _, b=body, m=model: body_moved(b, m)) def slider_moved(model, body): body.offset_x.value = model.as_float * 100 sub = model.subscribe_value_changed_fn(lambda m=model, b=body: slider_moved(m, b))
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_18/config/extension.toml
[package] # Semantic Versionning is used: https://semver.org/ version = "1.0.0" # The title and description fields are primarily for displaying extension info in UI title = "2022-11-18: Dev Office Hours" description="Sample code from the Dev Office Hour held on 2022-11-18" # Path (relative to the root) or content of readme markdown file for UI. readme = "docs/README.md" # URL of the extension source repository. repository = "" # One of categories for UI. category = "Example" # Keywords for the extension keywords = ["kit", "example"] # Use omni.ui to build simple UI [dependencies] "omni.kit.uiapp" = {} # Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_11_18". [[python.module]] name = "maticodes.doh_2022_11_18"
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_18/docs/README.md
# Developer Office Hour - 11/18/2022 This is the sample code from the Developer Office Hour held on 11/18/2022, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - How do I add widgets on top of the viewport? (ViewportWindow.get_frame) - How do I use value model with ui.Placer? - How do I see all of the code from the UI documentation examples?
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_07/maticodes/doh_2022_10_07/extension.py
# SPDX-License-Identifier: Apache-2.0 import carb import omni.ext import omni.ui as ui class MyWindow(ui.Window): def __init__(self, title: str = None, **kwargs): super().__init__(title, **kwargs) self.frame.set_build_fn(self._build_window) def _build_window(self): with ui.ScrollingFrame(): with ui.VStack(height=0): ui.Label("My Label") def clicked(): carb.log_info("Button Clicked!") ui.Button("Click Me", clicked_fn=clicked) class MyExtension(omni.ext.IExt): def on_startup(self, ext_id): carb.log_info("[maticodes.doh_2022_10_07] Dev Office Hours Extension (2022-10-07) startup") self._window = MyWindow("MyWindow", width=300, height=300) def on_shutdown(self): carb.log_info("[maticodes.doh_2022_10_07] Dev Office Hours Extension (2022-10-07) shutdown") if self._window: self._window.destroy() self._window = None
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_07/maticodes/doh_2022_10_07/__init__.py
# SPDX-License-Identifier: Apache-2.0 from .extension import *
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_07/scripts/usd_update_stream.py
# SPDX-License-Identifier: Apache-2.0 import omni.usd from pxr import UsdGeom, Gf stage = omni.usd.get_context().get_stage() cube = stage.GetPrimAtPath("/World/Cube") def print_pos(changed_path): print(changed_path) if changed_path.IsPrimPath(): prim_path = changed_path else: prim_path = changed_path.GetPrimPath() prim = stage.GetPrimAtPath(prim_path) world_transform = omni.usd.get_world_transform_matrix(prim) translation: Gf.Vec3d = world_transform.ExtractTranslation() rotation: Gf.Rotation = world_transform.ExtractRotation() scale: Gf.Vec3d = Gf.Vec3d(*(v.GetLength() for v in world_transform.ExtractRotationMatrix())) print(translation, rotation, scale) cube_move_sub = omni.usd.get_watcher().subscribe_to_change_info_path(cube.GetPath(), print_pos)
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_07/scripts/create_viewport.py
# SPDX-License-Identifier: Apache-2.0 import carb import omni.kit.viewport.utility as vp_utils from omni.kit.widget.viewport.api import ViewportAPI vp_window = vp_utils.create_viewport_window("My Viewport") vp_window.viewport_api.fill_frame = True vp_api: ViewportAPI = vp_window.viewport_api carb.settings.get_settings().set('/rtx/rendermode', "PathTracing") vp_api.set_hd_engine("rtx")
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_07/config/extension.toml
[package] # Semantic Versionning is used: https://semver.org/ version = "1.0.0" # The title and description fields are primarily for displaying extension info in UI title = "2022-10-07: Dev Office Hours" description="Sample code from the Dev Office Hour held on 2022-10-07" # Path (relative to the root) or content of readme markdown file for UI. readme = "docs/README.md" # URL of the extension source repository. repository = "" # One of categories for UI. category = "Example" # Keywords for the extension keywords = ["kit", "example"] # Use omni.ui to build simple UI [dependencies] "omni.kit.uiapp" = {} # Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_10_07". [[python.module]] name = "maticodes.doh_2022_10_07"
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_07/docs/README.md
# Developer Office Hour - 10/07/2022 This is the sample code from the Developer Office Hour held on 10/07/2022, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - How do I create another viewport? - How do I use the Script Node?
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_02/maticodes/doh_2022_12_02/extension.py
# SPDX-License-Identifier: Apache-2.0 import carb import omni.ext import omni.ui as ui class MyWindow(ui.Window): def __init__(self, title: str = None, **kwargs): super().__init__(title, **kwargs) self.frame.set_build_fn(self._build_window) def _build_window(self): with ui.ScrollingFrame(): with ui.VStack(height=0): with ui.HStack(height=0): ui.Label("My Label") MyCoolComponent() def clicked(): carb.log_info("Button Clicked!") ui.Button("Click Me", clicked_fn=clicked) class MyCoolComponent: def __init__(self): with ui.VStack(): ui.Label("Moar labels- asdfasdfasdf") ui.Label("Even moar labels") with ui.HStack(): ui.Button("Ok") ui.Button("Cancel") class MyExtension(omni.ext.IExt): def on_startup(self, ext_id): """_summary_ Args: ext_id (_type_): _description_ """ carb.log_info("[maticodes.doh_2022_12_02] Dev Office Hours Extension (2022-12-02) startup") self._window = MyWindow("MyWindow", width=300, height=300) def on_shutdown(self): carb.log_info("[maticodes.doh_2022_12_02] Dev Office Hours Extension (2022-12-02) shutdown") if self._window: self._window.destroy() self._window = None
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_02/maticodes/doh_2022_12_02/__init__.py
# SPDX-License-Identifier: Apache-2.0 from .extension import *
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_02/scripts/spawn_objects.py
# SPDX-License-Identifier: Apache-2.0 import carb.events import omni.kit.app import omni.kit.commands import logging time_since_last_create = 0 update_stream = omni.kit.app.get_app().get_update_event_stream() def on_update(e: carb.events.IEvent): global time_since_last_create carb.log_info(f"Update: {e.payload['dt']}") time_since_last_create += e.payload['dt'] carb.log_info(f"time since: {time_since_last_create}") if time_since_last_create > 2: carb.log_info("Creating cube") omni.kit.commands.execute('CreateMeshPrimWithDefaultXform', prim_type='Cube') time_since_last_create = 0 sub = update_stream.create_subscription_to_pop(on_update, name="My Subscription Name") sub = None
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_02/config/extension.toml
[package] # Semantic Versionning is used: https://semver.org/ version = "1.0.0" # The title and description fields are primarily for displaying extension info in UI title = "2022-12-02: Dev Office Hours" description="Sample code from the Dev Office Hour held on 2022-12-02" # Path (relative to the root) or content of readme markdown file for UI. readme = "docs/README.md" # URL of the extension source repository. repository = "" # One of categories for UI. category = "Example" # Keywords for the extension keywords = ["kit", "example"] # Use omni.ui to build simple UI [dependencies] "omni.kit.uiapp" = {} # Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_12_02". [[python.module]] name = "maticodes.doh_2022_12_02"
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_02/docs/README.md
# Developer Office Hour - 12/02/2022 This is the sample code from the Developer Office Hour held on 12/02/2022, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - How do I uninstall an extension? - How do I export USDZ? - Where is the extension I was working on? - How do I create complex UI without so much indented Python code?
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/maticodes/doh_2022_08_12/extension.py
# SPDX-License-Identifier: Apache-2.0 import carb import omni.ext from omni.kit.viewport.utility import get_active_viewport_window import omni.ui as ui from .viewport_scene import ViewportScene from .object_info_model import ObjectInfoModel class MyWindow(ui.Window): def __init__(self, title: str = None, delegate=None, **kwargs): super().__init__(title, **kwargs) self._viewport_scene = None self.obj_info_model = kwargs["obj_info_model"] self.frame.set_build_fn(self._build_window) def _build_window(self): with ui.ScrollingFrame(): with ui.VStack(height=0): ui.Label("My Label 2") ui.StringField() ui.StringField(password_mode=True) def clicked(): self.obj_info_model.populate() ui.Button("Reload Object Info", clicked_fn=clicked) def destroy(self) -> None: return super().destroy() 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): # Get the active Viewport (which at startup is the default Viewport) viewport_window = get_active_viewport_window() # Issue an error if there is no Viewport if not viewport_window: carb.log_error(f"No Viewport Window to add {ext_id} scene to") return # Build out the scene model = ObjectInfoModel() self._viewport_scene = ViewportScene(viewport_window, ext_id, model) self._window = MyWindow("MyWindow", obj_info_model=model, width=300, height=300) def on_shutdown(self): if self._window: self._window.destroy() self._window = None if self._viewport_scene: self._viewport_scene.destroy() self._viewport_scene = None
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/maticodes/doh_2022_08_12/viewport_scene.py
# SPDX-License-Identifier: Apache-2.0 # Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. # # NVIDIA CORPORATION and its licensors retain all intellectual property # and proprietary rights in and to this software, related documentation # and any modifications thereto. Any use, reproduction, disclosure or # distribution of this software and related documentation without an express # license agreement from NVIDIA CORPORATION is strictly prohibited. # __all__ = ["ViewportScene"] from omni.ui import scene as sc import omni.ui as ui from .object_info_manipulator import ObjectInfoManipulator class ViewportScene(): """The Object Info Manipulator, placed into a Viewport""" def __init__(self, viewport_window: ui.Window, ext_id: str, model) -> None: self._scene_view = None self._viewport_window = viewport_window # Create a unique frame for our SceneView with self._viewport_window.get_frame(ext_id): # Create a default SceneView (it has a default camera-model) self._scene_view = sc.SceneView() # Add the manipulator into the SceneView's scene with self._scene_view.scene: ObjectInfoManipulator(model=model) # Register the SceneView with the Viewport to get projection and view updates self._viewport_window.viewport_api.add_scene_view(self._scene_view) def __del__(self): self.destroy() def destroy(self): if self._scene_view: # Empty the SceneView of any elements it may have self._scene_view.scene.clear() # Be a good citizen, and un-register the SceneView from Viewport updates if self._viewport_window: self._viewport_window.viewport_api.remove_scene_view(self._scene_view) # Remove our references to these objects self._viewport_window = None self._scene_view = None
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/maticodes/doh_2022_08_12/__init__.py
# SPDX-License-Identifier: Apache-2.0 from .extension import *
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/maticodes/doh_2022_08_12/object_info_model.py
# SPDX-License-Identifier: Apache-2.0 # Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. # # NVIDIA CORPORATION and its licensors retain all intellectual property # and proprietary rights in and to this software, related documentation # and any modifications thereto. Any use, reproduction, disclosure or # distribution of this software and related documentation without an express # license agreement from NVIDIA CORPORATION is strictly prohibited. # __all__ = ["ObjectInfoModel"] from pxr import Tf from pxr import Usd from pxr import UsdGeom from omni.ui import scene as sc import omni.usd # The distance to raise above the top of the object's bounding box TOP_OFFSET = 5 class ObjectInfoModel(sc.AbstractManipulatorModel): """ The model tracks the position and info of the selected object. """ class PositionItem(sc.AbstractManipulatorItem): """ The Model Item represents the position. It doesn't contain anything because we take the position directly from USD when requesting. """ def __init__(self): super().__init__() self.value = [0, 0, 0] def __init__(self): super().__init__() # Current selected prim and material self._current_paths = [] self.positions = [] self._stage_listener = None self.populate() if not self._stage_listener: # This handles camera movement usd_context = self._get_context() stage = usd_context.get_stage() self._stage_listener = Tf.Notice.Register(Usd.Notice.ObjectsChanged, self._notice_changed, stage) def populate(self): self._current_paths = [] self.positions = [] usd_context = self._get_context() stage = usd_context.get_stage() prim = stage.GetPrimAtPath("/World/Labeled") if not prim.IsValid(): return for child in prim.GetChildren(): if child.IsA(UsdGeom.Imageable): self._current_paths.append(child.GetPath()) self.positions.append(ObjectInfoModel.PositionItem()) # Position is changed because new selected object has a different position self._item_changed(self.positions[-1]) def _get_context(self): # Get the UsdContext we are attached to return omni.usd.get_context() def _notice_changed(self, notice: Usd.Notice, stage: Usd.Stage) -> None: """Called by Tf.Notice. Used when the current selected object changes in some way.""" for p in notice.GetChangedInfoOnlyPaths(): for i, watched_path in enumerate(self._current_paths): if str(watched_path) in str(p.GetPrimPath()): self._item_changed(self.positions[i]) def get_name(self, index): return self._current_paths[index] def get_num_prims(self): return len(self._current_paths) def get_position(self, index): """Returns position of currently selected object""" stage = self._get_context().get_stage() if not stage or not self._current_paths[index]: return [0, 0, 0] # Get position directly from USD prim = stage.GetPrimAtPath(self._current_paths[index]) box_cache = UsdGeom.BBoxCache(Usd.TimeCode.Default(), includedPurposes=[UsdGeom.Tokens.default_]) bound = box_cache.ComputeWorldBound(prim) range = bound.ComputeAlignedBox() bboxMin = range.GetMin() bboxMax = range.GetMax() # Find the top center of the bounding box and add a small offset upward. position = [(bboxMin[0] + bboxMax[0]) * 0.5, bboxMax[1] + TOP_OFFSET, (bboxMin[2] + bboxMax[2]) * 0.5] return position
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/maticodes/doh_2022_08_12/object_info_manipulator.py
# SPDX-License-Identifier: Apache-2.0 # Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. # # NVIDIA CORPORATION and its licensors retain all intellectual property # and proprietary rights in and to this software, related documentation # and any modifications thereto. Any use, reproduction, disclosure or # distribution of this software and related documentation without an express # license agreement from NVIDIA CORPORATION is strictly prohibited. __all__ = ["ObjectInfoManipulator"] from omni.ui import color as cl from omni.ui import scene as sc import omni.ui as ui LEADER_LINE_CIRCLE_RADIUS = 2 LEADER_LINE_THICKNESS = 2 LEADER_LINE_SEGMENT_LENGTH = 20 VERTICAL_MULT = 1.5 HORIZ_TEXT_OFFSET = 5 LINE1_OFFSET = 3 LINE2_OFFSET = 0 class ObjectInfoManipulator(sc.Manipulator): """Manipulator that displays the object path and material assignment with a leader line to the top of the object's bounding box. """ def on_build(self): """Called when the model is changed and rebuilds the whole manipulator""" if not self.model: return for i in range(self.model.get_num_prims()): position = self.model.get_position(i) # Move everything to where the object is with sc.Transform(transform=sc.Matrix44.get_translation_matrix(*position)): # Rotate everything to face the camera with sc.Transform(look_at=sc.Transform.LookAt.CAMERA): # Leader lines with a small circle on the end sc.Arc(LEADER_LINE_CIRCLE_RADIUS, axis=2, color=cl.yellow) sc.Line([0, 0, 0], [0, LEADER_LINE_SEGMENT_LENGTH, 0], color=cl.yellow, thickness=LEADER_LINE_THICKNESS) sc.Line([0, LEADER_LINE_SEGMENT_LENGTH, 0], [LEADER_LINE_SEGMENT_LENGTH, LEADER_LINE_SEGMENT_LENGTH * VERTICAL_MULT, 0], color=cl.yellow, thickness=LEADER_LINE_THICKNESS) # Shift text to the end of the leader line with some offset with sc.Transform(transform=sc.Matrix44.get_translation_matrix( LEADER_LINE_SEGMENT_LENGTH + HORIZ_TEXT_OFFSET, LEADER_LINE_SEGMENT_LENGTH * VERTICAL_MULT, 0)): with sc.Transform(scale_to=sc.Space.SCREEN): # Offset each Label vertically in screen space with sc.Transform(transform=sc.Matrix44.get_translation_matrix(0, LINE1_OFFSET, 0)): sc.Label(f"Path: {self.model.get_name(i)}", alignment=ui.Alignment.LEFT_BOTTOM) def on_model_updated(self, item): # Regenerate the manipulator self.invalidate()
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/scripts/viewport_popup_notification.py
# SPDX-License-Identifier: Apache-2.0 # https://docs.omniverse.nvidia.com/py/kit/source/extensions/omni.kit.notification_manager/docs/index.html?highlight=omni%20kit%20notification_manager# import carb def clicked_ok(): carb.log_info("User clicked ok") def clicked_cancel(): carb.log_info("User clicked cancel") import omni.kit.notification_manager as nm ok_button = nm.NotificationButtonInfo("OK", on_complete=clicked_ok) cancel_button = nm.NotificationButtonInfo("CANCEL", on_complete=clicked_cancel) notification_info = nm.post_notification( "Notification Example", hide_after_timeout=False, duration=0, status=nm.NotificationStatus.WARNING, button_infos=[ok_button, cancel_button], )
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/scripts/create_many_prims.py
# SPDX-License-Identifier: Apache-2.0 from pxr import UsdGeom import omni.kit.commands import omni.usd stage = omni.usd.get_context().get_stage() cube_paths = [] for i in range(10): cube_path = omni.usd.get_stage_next_free_path(stage, "/World/Cube", prepend_default_prim=False) cube_paths.append(cube_path) omni.kit.commands.execute("CreatePrim", prim_type="Cube", prim_path=cube_path) # UsdGeom.Cube.Define(stage, cube_path)
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/scripts/refer_to_child_prim.py
# SPDX-License-Identifier: Apache-2.0 # https://docs.omniverse.nvidia.com/prod_usd/prod_usd/quick-start/hierarchy.html import omni.usd stage = omni.usd.get_context().get_stage() starting_prim = stage.GetPrimAtPath("/World/New") for shape in starting_prim.GetChildren(): print(shape) for shape_child in shape.GetChildren(): print(shape_child) for prim in stage.Traverse(): print(prim)
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/scripts/create_group_anywhere.py
# SPDX-License-Identifier: Apache-2.0 from pxr import Sdf import omni.kit.commands import omni.usd stage = omni.usd.get_context().get_stage() children = [] for i in range(3): child = omni.usd.get_stage_next_free_path(stage, "/World/Cube", prepend_default_prim=False) children.append(child) omni.kit.commands.execute("CreatePrim", prim_type="Cube", prim_path=child) group_path = Sdf.Path("/World/New/Hello") omni.kit.commands.execute("CreatePrimWithDefaultXformCommand", prim_type="Scope", prim_path=str(group_path)) for child in children: prim = stage.GetPrimAtPath(child) name = prim.GetName() omni.kit.commands.execute("MovePrim", path_from=child, path_to=group_path.AppendPath(name))
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/scripts/does_prim_exist.py
# SPDX-License-Identifier: Apache-2.0 from pxr import Usd, UsdGeom import omni.usd stage = omni.usd.get_context().get_stage() prim = stage.GetPrimAtPath("/World/New/Hello") print(prim) print(prim.IsValid()) prim = stage.GetPrimAtPath("/World/New/Fake") print(prim) print(prim.IsValid())
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/config/extension.toml
[package] # Semantic Versionning is used: https://semver.org/ version = "1.0.0" # The title and description fields are primarily for displaying extension info in UI title = "2022-08-12: Dev Office Hours" description="Sample code from the Dev Office Hour held on 2022-08-12" # Path (relative to the root) or content of readme markdown file for UI. readme = "docs/README.md" # URL of the extension source repository. repository = "" # One of categories for UI. category = "Example" # Keywords for the extension keywords = ["kit", "example"] # Use omni.ui to build simple UI [dependencies] "omni.kit.uiapp" = {} # Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_08_12". [[python.module]] name = "maticodes.doh_2022_08_12"
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/docs/README.md
# Developer Office Hour - 08/12/2022 This is the sample code from the Developer Office Hour held on 08/12/2022, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - How do I create many prims at available prim paths? - How do I create a group at a specific prim path? - Is there a way to check if a prim exists? - How do I refer to the child of a prim without giving the prim path? - How can I create a notification popup in the viewport with a log message? - How do I show labels in the viewport for multiple prims? ...