file_path
stringlengths 21
207
| content
stringlengths 5
1.02M
| size
int64 5
1.02M
| lang
stringclasses 9
values | avg_line_length
float64 2.5
98.5
| max_line_length
int64 5
993
| alphanum_fraction
float64 0.27
0.91
|
---|---|---|---|---|---|---|
mati-nvidia/window-menu-add/exts/maticodes.example.window.add/maticodes/example/window/add/window.py | import omni.kit.ui
import omni.ui as ui
WINDOW_TITLE = "My Custom Window"
class MyCustomWindow(ui.Window):
def __init__(self, title, menu_path):
super().__init__(title, width=640, height=480)
self._menu_path = menu_path
self.set_visibility_changed_fn(self._on_visibility_changed)
self._build_ui()
def on_shutdown(self):
self._win = None
def show(self):
self.visible = True
self.focus()
def hide(self):
self.visible = False
def _build_ui(self):
with self.frame:
with ui.VStack():
ui.Label("This is just an empty window", width=0, alignment=ui.Alignment.CENTER)
def _on_visibility_changed(self, visible):
omni.kit.ui.get_editor_menu().set_value(self._menu_path, visible)
| 809 | Python | 25.129031 | 96 | 0.606922 |
mati-nvidia/window-menu-add/exts/maticodes.example.window.add/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 = "Window Menu Add"
description="How to create a custom window and add it to the 'Window' menu"
# 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 omni.hello.world".
[[python.module]]
name = "maticodes.example.window.add"
| 773 | TOML | 25.689654 | 105 | 0.733506 |
mati-nvidia/window-menu-add/exts/maticodes.example.window.add/docs/README.md | # Window Menu Add
An example extension showing how to create a window and add it to the `Window` menu so that it can be shown and hidden
using the menu item in the `Window` menu. | 179 | Markdown | 43.999989 | 118 | 0.765363 |
mati-nvidia/developer-office-hours/RUNBOOK.md | 1. Run make_ext.bat <YYYY-MM-DD>
1. Put script into the `scripts/` folder.
1. Add questions covered in the ext README. | 118 | Markdown | 38.666654 | 43 | 0.728814 |
mati-nvidia/developer-office-hours/tools/scripts/csv2md.py | # SPDX-License-Identifier: Apache-2.0
import argparse
import csv
from pathlib import Path
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Convert DOH CSV to MD")
parser.add_argument(
"csvfile", help="The CSV file to convert"
)
args = parser.parse_args()
csvfile = Path(args.csvfile)
mdfile = csvfile.with_suffix(".md")
rows = []
with open(csvfile) as f:
with open(mdfile, "w") as out:
for row in csv.reader(f):
if row[2] and not row[5]:
out.write(f"1. [{row[1]}]({row[2]})\n")
print("Success!")
| 654 | Python | 20.833333 | 73 | 0.54893 |
mati-nvidia/developer-office-hours/tools/scripts/make_ext.py | # SPDX-License-Identifier: Apache-2.0
import argparse
import shutil
import os
from pathlib import Path
SOURCE_PATH = Path(__file__).parent / "template" / "maticodes.doh_YYYY_MM_DD"
def text_replace(filepath, tokens_map):
with open(filepath, "r") as f:
data = f.read()
for token, fstring in tokens_map.items():
data = data.replace(token, fstring)
with open(filepath, "w") as f:
f.write(data)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Create folder link to Kit App installed from Omniverse Launcher")
parser.add_argument(
"date", help="The dates of the Office Hour in YYYY-MM-DD format."
)
args = parser.parse_args()
year, month, day = args.date.split("-")
# copy files
dest_path = Path(__file__).parent / "../.." / f"exts/maticodes.doh_{year}_{month}_{day}"
shutil.copytree(SOURCE_PATH, dest_path)
# rename folders
template_ext_folder = dest_path / "maticodes" / "doh_YYYY_MM_DD"
ext_folder = dest_path / "maticodes" / f"doh_{year}_{month}_{day}"
os.rename(template_ext_folder, ext_folder)
tokens_map = {
"[DATE_HYPHEN]": f"{year}-{month}-{day}",
"[DATE_UNDERSCORE]": f"{year}_{month}_{day}",
"[DATE_PRETTY]": f"{month}/{day}/{year}",
}
# text replace extension.toml
ext_toml = dest_path / "config" / "extension.toml"
text_replace(ext_toml, tokens_map)
# text replace README
readme = dest_path / "docs" / "README.md"
text_replace(readme, tokens_map)
# text replace extension.py
ext_py = ext_folder / "extension.py"
text_replace(ext_py, tokens_map)
print("Success!")
| 1,695 | Python | 28.241379 | 115 | 0.614159 |
mati-nvidia/developer-office-hours/tools/scripts/link_app.py | import os
import argparse
import sys
import json
import packmanapi
import urllib3
def find_omniverse_apps():
http = urllib3.PoolManager()
try:
r = http.request("GET", "http://127.0.0.1:33480/components")
except Exception as e:
print(f"Failed retrieving apps from an Omniverse Launcher, maybe it is not installed?\nError: {e}")
sys.exit(1)
apps = {}
for x in json.loads(r.data.decode("utf-8")):
latest = x.get("installedVersions", {}).get("latest", "")
if latest:
for s in x.get("settings", []):
if s.get("version", "") == latest:
root = s.get("launch", {}).get("root", "")
apps[x["slug"]] = (x["name"], root)
break
return apps
def create_link(src, dst):
print(f"Creating a link '{src}' -> '{dst}'")
packmanapi.link(src, dst)
APP_PRIORITIES = ["code", "create", "view"]
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Create folder link to Kit App installed from Omniverse Launcher")
parser.add_argument(
"--path",
help="Path to Kit App installed from Omniverse Launcher, e.g.: 'C:/Users/bob/AppData/Local/ov/pkg/create-2021.3.4'",
required=False,
)
parser.add_argument(
"--app", help="Name of Kit App installed from Omniverse Launcher, e.g.: 'code', 'create'", required=False
)
args = parser.parse_args()
path = args.path
if not path:
print("Path is not specified, looking for Omniverse Apps...")
apps = find_omniverse_apps()
if len(apps) == 0:
print(
"Can't find any Omniverse Apps. Use Omniverse Launcher to install one. 'Code' is the recommended app for developers."
)
sys.exit(0)
print("\nFound following Omniverse Apps:")
for i, slug in enumerate(apps):
name, root = apps[slug]
print(f"{i}: {name} ({slug}) at: '{root}'")
if args.app:
selected_app = args.app.lower()
if selected_app not in apps:
choices = ", ".join(apps.keys())
print(f"Passed app: '{selected_app}' is not found. Specify one of the following found Apps: {choices}")
sys.exit(0)
else:
selected_app = next((x for x in APP_PRIORITIES if x in apps), None)
if not selected_app:
selected_app = next(iter(apps))
print(f"\nSelected app: {selected_app}")
_, path = apps[selected_app]
if not os.path.exists(path):
print(f"Provided path doesn't exist: {path}")
else:
SCRIPT_ROOT = os.path.dirname(os.path.realpath(__file__))
create_link(f"{SCRIPT_ROOT}/../../app", path)
print("Success!")
| 2,813 | Python | 32.5 | 133 | 0.562389 |
mati-nvidia/developer-office-hours/tools/scripts/template/maticodes.doh_YYYY_MM_DD/maticodes/doh_YYYY_MM_DD/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_[DATE_UNDERSCORE]] Dev Office Hours Extension ([DATE_HYPHEN]) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_[DATE_UNDERSCORE]] Dev Office Hours Extension ([DATE_HYPHEN]) shutdown")
if self._window:
self._window.destroy()
self._window = None
| 1,025 | Python | 29.17647 | 110 | 0.599024 |
mati-nvidia/developer-office-hours/tools/scripts/template/maticodes.doh_YYYY_MM_DD/maticodes/doh_YYYY_MM_DD/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
| 64 | Python | 15.249996 | 37 | 0.75 |
mati-nvidia/developer-office-hours/tools/scripts/template/maticodes.doh_YYYY_MM_DD/scripts/my_script.py | # SPDX-License-Identifier: Apache-2.0 | 37 | Python | 36.999963 | 37 | 0.783784 |
mati-nvidia/developer-office-hours/tools/scripts/template/maticodes.doh_YYYY_MM_DD/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 = "[DATE_HYPHEN]: Dev Office Hours"
description="Sample code from the Dev Office Hour held on [DATE_HYPHEN]"
# 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_[DATE_UNDERSCORE]".
[[python.module]]
name = "maticodes.doh_[DATE_UNDERSCORE]"
| 804 | TOML | 26.75862 | 120 | 0.733831 |
mati-nvidia/developer-office-hours/tools/scripts/template/maticodes.doh_YYYY_MM_DD/docs/README.md | # Developer Office Hour - [DATE_PRETTY]
This is the sample code from the Developer Office Hour held on [DATE_PRETTY], Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- How do I do something?
...
| 282 | Markdown | 34.374996 | 117 | 0.762411 |
mati-nvidia/developer-office-hours/tools/packman/config.packman.xml | <config remotes="cloudfront">
<remote2 name="cloudfront">
<transport actions="download" protocol="https" packageLocation="d4i3qtqj3r0z5.cloudfront.net/${name}@${version}" />
</remote2>
</config>
| 211 | XML | 34.333328 | 123 | 0.691943 |
mati-nvidia/developer-office-hours/tools/packman/bootstrap/install_package.py | # Copyright 2019 NVIDIA CORPORATION
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import zipfile
import tempfile
import sys
import shutil
__author__ = "hfannar"
logging.basicConfig(level=logging.WARNING, format="%(message)s")
logger = logging.getLogger("install_package")
class TemporaryDirectory:
def __init__(self):
self.path = None
def __enter__(self):
self.path = tempfile.mkdtemp()
return self.path
def __exit__(self, type, value, traceback):
# Remove temporary data created
shutil.rmtree(self.path)
def install_package(package_src_path, package_dst_path):
with zipfile.ZipFile(
package_src_path, allowZip64=True
) as zip_file, TemporaryDirectory() as temp_dir:
zip_file.extractall(temp_dir)
# Recursively copy (temp_dir will be automatically cleaned up on exit)
try:
# Recursive copy is needed because both package name and version folder could be missing in
# target directory:
shutil.copytree(temp_dir, package_dst_path)
except OSError as exc:
logger.warning(
"Directory %s already present, packaged installation aborted" % package_dst_path
)
else:
logger.info("Package successfully installed to %s" % package_dst_path)
install_package(sys.argv[1], sys.argv[2])
| 1,888 | Python | 31.568965 | 103 | 0.68697 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_06/maticodes/doh_2023_01_06/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_06] Dev Office Hours Extension (2023-01-06) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_01_06] Dev Office Hours Extension (2023-01-06) shutdown")
if self._window:
self._window.destroy()
self._window = None
| 1,005 | Python | 28.588234 | 100 | 0.595025 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_06/maticodes/doh_2023_01_06/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
| 64 | Python | 15.249996 | 37 | 0.75 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_06/scripts/query_script_components.py | # SPDX-License-Identifier: Apache-2.0
from pxr import Sdf
import omni.usd
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/Cube")
attr = prim.GetAttribute("omni:scripting:scripts")
if attr.IsValid():
scripts = attr.Get()
if scripts:
for script in scripts:
print(script) | 327 | Python | 26.333331 | 50 | 0.685015 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_06/scripts/add_script_component.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
from pxr import Sdf
import omni.usd
omni.kit.commands.execute('ApplyScriptingAPICommand',
paths=[Sdf.Path('/World/Cube')])
omni.kit.commands.execute('RefreshScriptingPropertyWindowCommand')
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/Cube")
attr = prim.GetAttribute("omni:scripting:scripts")
scripts = attr.Get()
attr.Set([r"C:\Users\mcodesal\Downloads\new_script2.py"])
# attr.Set(["omniverse://localhost/Users/mcodesal/new_script2.py"])
omni.kit.commands.execute('ChangeProperty',
prop_path=Sdf.Path('/World/Cube.omni:scripting:scripts'),
value=Sdf.AssetPathArray(1, (Sdf.AssetPath('C:\\mcodesal\\Downloads\\new_script2.py'))),
prev=None)
attr = prim.GetAttribute("omni:scripting:scripts")
scripts = list(attr.Get())
scripts.append(r"C:\mcodesal\Downloads\new_script.py")
attr.Set(scripts)
| 899 | Python | 31.142856 | 89 | 0.757508 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_06/scripts/interact_script_components.py | # SPDX-License-Identifier: Apache-2.0
import carb.events
import omni.kit.app
MY_CUSTOM_EVENT = carb.events.type_from_string("omni.my.extension.MY_CUSTOM_EVENT")
bus = omni.kit.app.get_app().get_message_bus_event_stream()
bus.push(MY_CUSTOM_EVENT, payload={"prim_path": "/World/Cube", "x": 1}) | 295 | Python | 31.888885 | 83 | 0.728814 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_06/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-06: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-01-06"
# 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_06".
[[python.module]]
name = "maticodes.doh_2023_01_06"
| 784 | TOML | 26.068965 | 113 | 0.732143 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_06/docs/README.md | # Developer Office Hour - 01/06/2023
This is the sample code from the Developer Office Hour held on 01/06/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- 3:47 - How do you add an extension via the Extension Manager?
- 8:48 - How do you programmatically add a Python Script to a prim? (Python Scripting Component)
- 23:45 - How do you check what Python scripts a prim has? (Python Scripting Component)
- 27:00 - How can you have your extension interact with a Python Scripting Component?
| 583 | Markdown | 52.090904 | 114 | 0.768439 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_21/maticodes/doh_2023_04_21/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_04_21] Dev Office Hours Extension (2023-04-21) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_04_21] Dev Office Hours Extension (2023-04-21) shutdown")
if self._window:
self._window.destroy()
self._window = None
| 1,005 | Python | 28.588234 | 100 | 0.595025 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_21/maticodes/doh_2023_04_21/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
| 64 | Python | 15.249996 | 37 | 0.75 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_21/scripts/pass_arg_to_callback.py | # SPDX-License-Identifier: Apache-2.0
from functools import partial
import omni.ui as ui
def do_something(p1, p2):
print(f"Hello {p1} {p2}")
window = ui.Window("My Window", width=300, height=300)
with window.frame:
ui.Button("Click Me", clicked_fn=partial(do_something, "a", "b")) | 290 | Python | 25.454543 | 69 | 0.696552 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_21/scripts/create_mdl_mtl.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
omni.kit.commands.execute('CreateAndBindMdlMaterialFromLibrary',
mdl_name='OmniPBR.mdl',
mtl_name='OmniPBR',
mtl_created_list=None) | 198 | Python | 27.428568 | 64 | 0.787879 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_21/scripts/lock_prim.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
from pxr import Sdf
omni.kit.commands.execute('LockSpecs',
spec_paths=['/Desk'],
hierarchy=False) | 164 | Python | 19.624998 | 38 | 0.756098 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_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 = "2023-04-21: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-04-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_2023_04_21".
[[python.module]]
name = "maticodes.doh_2023_04_21"
| 784 | TOML | 26.068965 | 113 | 0.732143 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_21/docs/README.md | # Developer Office Hour - 04/21/2023
This is the sample code from the Developer Office Hour held on 04/21/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- 2:02 - How do I change the label of an Action Graph UI button?
- 17:29 - How do I style and Action Graph UI Button?
- 30:36 - How do I pass extra parameters to a button's clicked_fn callback?
- 40:00 - How do I programmatically Lock Selected for a prim?
- 44:08 - How do I create an MDL material on a stage?
| 558 | Markdown | 49.818177 | 114 | 0.74552 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_14/maticodes/doh_2023_04_14/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_04_14] Dev Office Hours Extension (2023-04-14) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_04_14] Dev Office Hours Extension (2023-04-14) shutdown")
if self._window:
self._window.destroy()
self._window = None
| 1,005 | Python | 28.588234 | 100 | 0.595025 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_14/maticodes/doh_2023_04_14/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
| 64 | Python | 15.249996 | 37 | 0.75 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_14/scripts/toggle_fullscreen.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.actions.core
action_registry = omni.kit.actions.core.get_action_registry()
action = action_registry.get_action("omni.kit.ui.editor_menu_bridge", "action_editor_menu_bridge_window_fullscreen_mode")
action.execute() | 269 | Python | 37.571423 | 121 | 0.784387 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_14/scripts/move_prim_forward.py | # SPDX-License-Identifier: Apache-2.0
from pxr import Gf, UsdGeom, Usd
import omni.usd
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/Camera")
xform = UsdGeom.Xformable(prim)
local_transformation: Gf.Matrix4d = xform.GetLocalTransformation()
# Apply the local matrix to the start and end points of the camera's default forward vector (-Z)
a: Gf.Vec4d = Gf.Vec4d(0,0,0,1) * local_transformation
b: Gf.Vec4d = Gf.Vec4d(0,0,-1,1) * local_transformation
# Get the vector between those two points to get the camera's current forward vector
cam_fwd_vec = b-a
# Convert to Vec3 and then normalize to get unit vector
cam_fwd_unit_vec = Gf.Vec3d(cam_fwd_vec[:3]).GetNormalized()
# Multiply the forward direction vector with how far forward you want to move
forward_step = cam_fwd_unit_vec * 100
# Create a new matrix with the translation that you want to perform
offset_mat = Gf.Matrix4d()
offset_mat.SetTranslate(forward_step)
# Apply the translation to the current local transform
new_transform = local_transformation * offset_mat
# Extract the new translation
translate: Gf.Vec3d = new_transform.ExtractTranslation()
# Update the attribute
prim.GetAttribute("xformOp:translate").Set(translate) | 1,220 | Python | 44.222221 | 96 | 0.769672 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_14/scripts/execute_action.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.actions.core
action_registry = omni.kit.actions.core.get_action_registry()
action = action_registry.get_action("ext_id", "action_id")
action.execute() | 206 | Python | 28.571424 | 61 | 0.762136 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_14/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-04-14: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-04-14"
# 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_04_14".
[[python.module]]
name = "maticodes.doh_2023_04_14"
| 784 | TOML | 26.068965 | 113 | 0.732143 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_14/docs/README.md | # Developer Office Hour - 04/14/2023
This is the sample code from the Developer Office Hour held on 04/14/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- How do I find and execute a Kit Action?
- How do I programatically toggle fullscreen mode?
- How do I move a prim in the forward direction? | 388 | Markdown | 47.624994 | 114 | 0.775773 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_13/maticodes/doh_2023_01_13/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_13] Dev Office Hours Extension (2023-01-13) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_01_13] Dev Office Hours Extension (2023-01-13) shutdown")
if self._window:
self._window.destroy()
self._window = None
| 1,005 | Python | 28.588234 | 100 | 0.595025 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_13/maticodes/doh_2023_01_13/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
| 64 | Python | 15.249996 | 37 | 0.75 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_13/scripts/add_script_component.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
from pxr import Sdf
import omni.usd
# Create the Python Scripting Component property
omni.kit.commands.execute('ApplyScriptingAPICommand',
paths=[Sdf.Path('/World/Cube')])
omni.kit.commands.execute('RefreshScriptingPropertyWindowCommand')
# Add your script to the property
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/Cube")
attr = prim.GetAttribute("omni:scripting:scripts")
scripts = attr.Get()
# Property with no script paths returns None
if scripts is None:
scripts = []
else:
# Property with scripts paths returns VtArray.
# Convert to list to make it easier to work with.
scripts = list(scripts)
scripts.append(r"C:\Users\mcodesal\Downloads\new_script.py")
attr.Set(scripts)
| 785 | Python | 29.230768 | 66 | 0.769427 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_13/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-13: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-01-13"
# 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_13".
[[python.module]]
name = "maticodes.doh_2023_01_13"
| 784 | TOML | 26.068965 | 113 | 0.732143 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_13/docs/README.md | # Developer Office Hour - 01/13/2023
This is the sample code from the Developer Office Hour held on 01/13/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- 3:46 - How do you programmatically add a Python Script to a prim? (Python Scripting Component)
- 8:02 - What are the criteria for valid prim and property names in USD?
- 11:14 - How can I swap a prim's material using Action Graph? | 479 | Markdown | 58.999993 | 114 | 0.76618 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_06_23/maticodes/doh_2023_06_23/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_06_23] Dev Office Hours Extension (2023-06-23) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_06_23] Dev Office Hours Extension (2023-06-23) shutdown")
if self._window:
self._window.destroy()
self._window = None
| 1,005 | Python | 28.588234 | 100 | 0.595025 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_06_23/maticodes/doh_2023_06_23/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
| 64 | Python | 15.249996 | 37 | 0.75 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_06_23/scripts/select_prims.py | # SPDX-License-Identifier: Apache-2.0
import omni.usd
stage = omni.usd.get_context().get_stage()
ctx = omni.usd.get_context()
selection: omni.usd.Selection = ctx.get_selection()
selection.set_selected_prim_paths(["/World/Cube", "/World/Sphere"], False)
import omni.kit.commands
import omni.usd
ctx = omni.usd.get_context()
selection: omni.usd.Selection = ctx.get_selection()
omni.kit.commands.execute('SelectPrimsCommand',
old_selected_paths=selection.get_selected_prim_paths(),
new_selected_paths=["/World/Cone"],
expand_in_stage=True)
| 547 | Python | 23.90909 | 74 | 0.744058 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_06_23/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-06-23: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-06-23"
# 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_06_23".
[[python.module]]
name = "maticodes.doh_2023_06_23"
| 784 | TOML | 26.068965 | 113 | 0.732143 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_06_23/docs/README.md | # Developer Office Hour - 06/23/2023
This is the sample code from the Developer Office Hour held on 06/23/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- 03:50 - How do programmatically select a prim?
- 16:00 - How do I reset the settings and preferences for a Kit app?
| 365 | Markdown | 44.749994 | 114 | 0.767123 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_27/maticodes/doh_2023_01_27/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_27] Dev Office Hours Extension (2023-01-27) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_01_27] Dev Office Hours Extension (2023-01-27) shutdown")
if self._window:
self._window.destroy()
self._window = None
| 1,005 | Python | 28.588234 | 100 | 0.595025 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_27/maticodes/doh_2023_01_27/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
| 64 | Python | 15.249996 | 37 | 0.75 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_27/scripts/sub_child_changes.py | # SPDX-License-Identifier: Apache-2.0
# UsdWatcher
from pxr import Sdf, Tf, Usd
import omni.usd
stage = omni.usd.get_context().get_stage()
def changed_paths(notice, stage):
print("Change fired")
for p in notice.GetChangedInfoOnlyPaths():
if str(p).startswith("/World/Parent" + "/"):
print("Something happened to a descendent of /World/Parent")
print(p)
for p in notice.GetResyncedPaths():
if str(p).startswith("/World/Parent" + "/"):
print("A descendent of /World/Parent was added or removed")
print(p)
objects_changed = Tf.Notice.Register(Usd.Notice.ObjectsChanged, changed_paths, None)
objects_changed.Revoke()
| 696 | Python | 26.879999 | 84 | 0.656609 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_27/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-27: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-01-27"
# 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_27".
[[python.module]]
name = "maticodes.doh_2023_01_27"
| 784 | TOML | 26.068965 | 113 | 0.732143 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_01_27/docs/README.md | # Developer Office Hour - 01/27/2023
This is the sample code from the Developer Office Hour held on 01/27/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- 3:14 - How do I listen for changes to the children of a certain prim?
- 15:00 - How do I rotate a prim using Action Graph?
| 372 | Markdown | 45.624994 | 114 | 0.760753 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_07_22/maticodes/doh_2022_07_22/extension.py | # SPDX-License-Identifier: Apache-2.0
import omni.ext
import omni.ui as ui
from omni.kit.widget.searchable_combobox import build_searchable_combo_widget
class MyWindow(ui.Window):
def __init__(self, title: str = None, delegate=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.proj_scale_model = ui.SimpleFloatModel()
self.proj_scale_model_sub = (
self.proj_scale_model.subscribe_value_changed_fn(
self.slider_value_changed
)
)
ui.FloatSlider(model=self.proj_scale_model, min=0, max=100)
def do_rebuild():
self.frame.rebuild()
ui.Button("Rebuild", clicked_fn=do_rebuild)
def clicked():
# Example showing how to retreive the value from the model.
print(
f"Button Clicked! Slider Value: {self.proj_scale_model.as_float}"
)
self.proj_scale_model.set_value(1.0)
ui.Button("Set Slider", clicked_fn=clicked)
def on_combo_click_fn(model):
component = model.get_value_as_string()
print(f"{component} selected")
component_list = ["Synthetic Data", "USD", "Kit", "UX", "UX / UI"]
component_index = -1
self._component_combo = build_searchable_combo_widget(
component_list,
component_index,
on_combo_click_fn,
widget_height=18,
default_value="Kit",
)
def slider_value_changed(self, model):
# Example showing how to get the value when it changes.
print("Slider Value:", model.as_float)
def destroy(self) -> None:
del self.proj_scale_model_sub
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):
print(
"[maticodes.doh_2022_07_22] Dev Office Hours Extension (2022-07-22) startup"
)
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
print(
"[maticodes.doh_2022_07_22] Dev Office Hours Extension (2022-07-22) shutdown"
)
if self._window:
self._window.destroy()
self._window = None
| 2,804 | Python | 34.961538 | 119 | 0.542083 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_07_22/maticodes/doh_2022_07_22/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
| 63 | Python | 20.333327 | 37 | 0.761905 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_07_22/scripts/cmds_more_params.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
from pxr import Gf, Usd
omni.kit.commands.execute('SetAnimCurveKey',
paths=['/World/toy_drummer.xformOp:translate'],
value=Gf.Vec3d(0.0, 0.0, 18))
omni.kit.commands.execute('SetAnimCurveKey',
paths=['/World/toy_drummer.xformOp:translate'],
value=Gf.Vec3d(0.0, 0.0, 24),
time=Usd.TimeCode(72))
| 365 | Python | 23.399998 | 48 | 0.731507 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_07_22/scripts/set_current_time.py | # SPDX-License-Identifier: Apache-2.0
# https://docs.omniverse.nvidia.com/py/kit/source/extensions/omni.timeline/docs/index.html
import omni.timeline
timeline = omni.timeline.get_timeline_interface()
# set in using seconds
timeline.set_current_time(1)
# set using frame number
fps = timeline.get_time_codes_per_seconds()
timeline.set_current_time(48 / fps)
| 360 | Python | 26.769229 | 90 | 0.775 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_07_22/scripts/reference_usdz.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
from pxr import Sdf
import omni.usd
omni.kit.commands.execute('CreateReference',
path_to=Sdf.Path('/World/toy_drummer2'),
asset_path='C:/Users/mcodesal/Downloads/toy_drummer.usdz',
usd_context=omni.usd.get_context())
| 287 | Python | 21.153845 | 59 | 0.759582 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_07_22/scripts/run_action_graph.py | # SPDX-License-Identifier: Apache-2.0
# https://docs.omniverse.nvidia.com/py/kit/source/extensions/omni.graph/docs/index.html
import omni.graph.core as og
keys = og.Controller.Keys
og.Controller.edit("/World/ActionGraph", { keys.SET_VALUES: ("/World/ActionGraph/on_impulse_event.state:enableImpulse", True) })
| 313 | Python | 33.888885 | 128 | 0.763578 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_07_22/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-07-22: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2022-07-22"
# 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_07_22".
[[python.module]]
name = "maticodes.doh_2022_07_22"
| 784 | TOML | 26.068965 | 113 | 0.732143 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_07_22/docs/README.md | # Developer Office Hour - 07/22/2022
This is the sample code from the Developer Office Hour held on 07/22/2022, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- How do I reference a USDZ file?
- How do I look up all of the parameters for a Kit Command?
- How do I set the current frame using Python?
- How do I execute an Action Graph using Python?
- How do I align radio buttons horizontally?
- How do I refresh a UI window?
- How do I customize the appearance of a slider?
| 563 | Markdown | 42.384612 | 114 | 0.760213 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_14/maticodes/doh_2022_10_14/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):
def hello():
print("Hello")
ui.Button("Click Me", clicked_fn=hello)
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2022_10_14] Dev Office Hours Extension (2022-10-14) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2022_10_14] Dev Office Hours Extension (2022-10-14) shutdown")
if self._window:
self._window.destroy()
self._window = None
| 848 | Python | 28.275861 | 100 | 0.621462 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_14/maticodes/doh_2022_10_14/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
| 64 | Python | 15.249996 | 37 | 0.75 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_14/scripts/context_menu_inject.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.context_menu
def show_menu(objects):
print("show it?")
return True
def hello_world(objects):
print(f"Hello Objects: {objects}")
menu_item_config = {
"name": "Hello World!",
"glyph": "menu_search.svg",
"show_fn": [show_menu],
"onclick_fn": hello_world,
}
# You must keep a reference to the menu item. Set this variable to None to remove the item from the menu
hello_world_menu_item = omni.kit.context_menu.add_menu(menu_item_config, "MENU", "omni.kit.window.viewport")
hello_world_menu_item = None | 583 | Python | 26.809523 | 108 | 0.687822 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_14/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-14: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2022-10-14"
# 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" = {}
#"foo.bar" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_10_14".
[[python.module]]
name = "maticodes.doh_2022_10_14"
| 800 | TOML | 25.699999 | 113 | 0.725 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_14/docs/README.md | # Developer Office Hour - 10/14/2022
This is the sample code from the Developer Office Hour held on 10/14/2022, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- Why doesn't OV Code start?
- How do I inject my custom menu item into an existing context menu?
| 345 | Markdown | 42.249995 | 114 | 0.773913 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_25/maticodes/doh_2023_08_25/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_08_25] Dev Office Hours Extension (2023-08-25) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_08_25] Dev Office Hours Extension (2023-08-25) shutdown")
if self._window:
self._window.destroy()
self._window = None
| 1,005 | Python | 28.588234 | 100 | 0.595025 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_25/maticodes/doh_2023_08_25/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
| 64 | Python | 15.249996 | 37 | 0.75 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_25/scripts/add_sbsar.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
omni.kit.commands.execute('AddSbsarReferenceAndBindCommand', sbsar_path=r"C:\Users\mcodesal\Downloads\blueberry_skin.sbsar",
target_prim_path="/World/Sphere")
| 252 | Python | 35.142852 | 124 | 0.710317 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_25/scripts/get_selected_meshes.py | # SPDX-License-Identifier: Apache-2.0
import omni.usd
from pxr import Usd, UsdGeom
stage = omni.usd.get_context().get_stage()
selection = omni.usd.get_context().get_selection().get_selected_prim_paths()
meshes = []
for path in selection:
prim = stage.GetPrimAtPath(path)
if prim.IsA(UsdGeom.Mesh):
meshes.append(prim)
print("Selected meshes:")
print(meshes) | 377 | Python | 22.624999 | 76 | 0.713528 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_25/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-08-25: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-08-25"
# 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_08_25".
[[python.module]]
name = "maticodes.doh_2023_08_25"
| 784 | TOML | 26.068965 | 113 | 0.732143 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_25/docs/README.md | # Developer Office Hour - 08/25/2023
This is the sample code from the Developer Office Hour held on 08/25/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- 02:17 - How do I get just the mesh prims from my current selection?
- 08:26 - How do I programmatically add an SBSAR material to my USD Stage?
| 392 | Markdown | 48.124994 | 114 | 0.767857 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/maticodes/doh_2023_04_28/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_04_28] Dev Office Hours Extension (2023-04-28) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_04_28] Dev Office Hours Extension (2023-04-28) shutdown")
if self._window:
self._window.destroy()
self._window = None
| 1,005 | Python | 28.588234 | 100 | 0.595025 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/maticodes/doh_2023_04_28/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
| 64 | Python | 15.249996 | 37 | 0.75 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/scripts/toggle_hud.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.viewport.utility as okvu
okvu.toggle_global_visibility() | 112 | Python | 21.599996 | 40 | 0.794643 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/scripts/custom_attrs.py |
# SPDX-License-Identifier: Apache-2.0
# Docs: https://docs.omniverse.nvidia.com/prod_kit/prod_kit/programmer_ref/usd/properties/create-attribute.html
import omni.usd
from pxr import Usd, Sdf
stage = omni.usd.get_context().get_stage()
prim: Usd.Prim = stage.GetPrimAtPath("/World/Cylinder")
attr: Usd.Attribute = prim.CreateAttribute("mySecondAttr", Sdf.ValueTypeNames.Bool)
attr.Set(False)
| 394 | Python | 29.384613 | 111 | 0.769036 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/scripts/custom_global_data.py | # SPDX-License-Identifier: Apache-2.0
import omni.usd
stage = omni.usd.get_context().get_stage()
layer = stage.GetRootLayer()
print(type(layer))
layer.SetCustomLayerData({"Hello": "World"})
stage.DefinePrim("/World/Hello", "HelloWorld")
stage.DefinePrim("/World/MyTypeless") | 278 | Python | 22.249998 | 46 | 0.741007 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/scripts/make_unselectable.py | # SPDX-License-Identifier: Apache-2.0
# Docs: https://docs.omniverse.nvidia.com/kit/docs/omni.usd/latest/omni.usd/omni.usd.UsdContext.html#omni.usd.UsdContext.set_pickable
import omni.usd
ctx = omni.usd.get_context()
ctx.set_pickable("/", True) | 247 | Python | 29.999996 | 133 | 0.757085 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/scripts/change_viewport_camera.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.viewport.utility as vu
from pxr import Sdf
vp_api = vu.get_active_viewport()
vp_api.camera_path = "/World/Camera_01"
| 173 | Python | 20.749997 | 39 | 0.745665 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/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-04-28: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-04-28"
# 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_04_28".
[[python.module]]
name = "maticodes.doh_2023_04_28"
| 784 | TOML | 26.068965 | 113 | 0.732143 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/docs/README.md | # Developer Office Hour - 04/28/2023
This is the sample code from the Developer Office Hour held on 04/28/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- 02:18 - How do I make a prim unselectable in the viewport?
- 07:50 - How do I create custom properties?
- 26:00 - Can I write custom components for prims link in Unity?
- 50:21 - How can I toggle the stats heads up display on the viewport?
- 66:00 - How can you switch cameras on the active viewport?
| 550 | Markdown | 49.090905 | 114 | 0.754545 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_01/maticodes/doh_2023_09_01/extension.py | # SPDX-License-Identifier: Apache-2.0
import subprocess
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!")
result = subprocess.check_output(["python", "-c", "print('Hello World')"])
print(result.decode())
ui.Button("Click Me", clicked_fn=clicked)
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2023_09_01] Dev Office Hours Extension (2023-09-01) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_09_01] Dev Office Hours Extension (2023-09-01) shutdown")
if self._window:
self._window.destroy()
self._window = None
| 1,162 | Python | 29.605262 | 100 | 0.585198 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_01/maticodes/doh_2023_09_01/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
| 64 | Python | 15.249996 | 37 | 0.75 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_01/scripts/logging.py | # SPDX-License-Identifier: Apache-2.0
import logging
import carb
logger = logging.getLogger()
print("Hello")
carb.log_info("World")
logger.info("Omniverse")
| 164 | Python | 9.999999 | 37 | 0.72561 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_01/scripts/xforming.py | # SPDX-License-Identifier: Apache-2.0
from pxr import UsdGeom
import omni.usd
stage = omni.usd.get_context().get_stage()
cube = stage.GetPrimAtPath("/World/Xform/Cube")
cube_xformable = UsdGeom.Xformable(cube)
transform = cube_xformable.GetLocalTransformation()
print(transform)
transform2 = cube_xformable.GetLocalTransformation()
print(transform2)
| 355 | Python | 21.249999 | 52 | 0.785915 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_01/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-09-01: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-09-01"
# 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_09_01".
[[python.module]]
name = "maticodes.doh_2023_09_01"
| 784 | TOML | 26.068965 | 113 | 0.732143 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_01/docs/README.md | # Developer Office Hour - 09/01/2023
This is the sample code from the Developer Office Hour held on 09/01/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- 7:27 - How do I validate my assets to make sure they are up-to-date with the latest USD specification?
| 352 | Markdown | 49.428564 | 114 | 0.775568 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_28/maticodes/doh_2022_10_28/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_28] Dev Office Hours Extension (2022-10-28) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
import omni.kit.commands
omni.kit.commands.execute('CreateMeshPrimWithDefaultXform',
prim_type='Cone')
from pxr import UsdGeom
stage = omni.usd.get_context().get_stage()
sphere = UsdGeom.Sphere.Define(stage, "/World/MySphere")
def on_shutdown(self):
carb.log_info("[maticodes.doh_2022_10_28] Dev Office Hours Extension (2022-10-28) shutdown")
if self._window:
self._window.destroy()
self._window = None
| 1,287 | Python | 28.953488 | 100 | 0.602953 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_28/maticodes/doh_2022_10_28/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
| 64 | Python | 15.249996 | 37 | 0.75 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_28/scripts/usd_watcher.py | # SPDX-License-Identifier: Apache-2.0
import omni.usd
from pxr import Gf
stage = omni.usd.get_context().get_stage()
cube = stage.GetPrimAtPath("/World/Cube")
def print_size(changed_path):
print("Size Changed:", changed_path)
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)
local_transform = omni.usd.get_local_transform_SRT(prim)
print("Translation: ", local_transform[3])
def print_world_pos(changed_path):
world_transform: Gf.Matrix4d = omni.usd.get_world_transform_matrix(prim)
translation: Gf.Vec3d = world_transform.ExtractTranslation()
print(translation)
size_attr = cube.GetAttribute("size")
cube_sub = omni.usd.get_watcher().subscribe_to_change_info_path(cube.GetPath(), print_world_pos)
cube_size_sub = omni.usd.get_watcher().subscribe_to_change_info_path(size_attr.GetPath(), print_size)
cube_sub = None
cube_size_sub = None | 1,040 | Python | 31.531249 | 101 | 0.714423 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_28/scripts/extras.py | # SPDX-License-Identifier: Apache-2.0
import omni.usd
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/Cube")
if prim:
print("Prim Exists")
from pxr import UsdGeom
# e.g., find all prims of type UsdGeom.Mesh
mesh_prims = [x for x in stage.Traverse() if x.IsA(UsdGeom.Mesh)]
mesh_prims = []
for x in stage.Traverse():
if x.IsA(UsdGeom.Mesh):
mesh_prims.append(x)
print(mesh_prims) | 432 | Python | 23.055554 | 65 | 0.685185 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_28/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.2)
my_window.deferred_dock_in("Content", ui.DockPolicy.TARGET_WINDOW_IS_ACTIVE)
| 548 | Python | 26.449999 | 81 | 0.717153 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_28/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-28: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2022-10-28"
# 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_28".
[[python.module]]
name = "maticodes.doh_2022_10_28"
| 784 | TOML | 26.068965 | 113 | 0.732143 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_28/docs/README.md | # Developer Office Hour - 10/28/2022
This is the sample code from the Developer Office Hour held on 10/28/2022, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- How do I dock my window?
- How do I subscribe to changes to a prim or attribute? (omni.usd.get_watcher())
| 355 | Markdown | 43.499995 | 114 | 0.76338 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/maticodes/doh_2022_09_23/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_23] Dev Office Hours Extension (2022-09-23) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2022_09_23] Dev Office Hours Extension (2022-09-23) shutdown")
if self._window:
self._window.destroy()
self._window = None
| 1,005 | Python | 28.588234 | 100 | 0.595025 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/maticodes/doh_2022_09_23/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
| 64 | Python | 15.249996 | 37 | 0.75 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/scripts/combobox_selected_item.py | # SPDX-License-Identifier: Apache-2.0
import omni.ui as ui
my_window = ui.Window("Example Window", width=300, height=300)
combo_sub = None
options = ["One", "Two", "Three"]
with my_window.frame:
with ui.VStack():
combo_model: ui.AbstractItemModel = ui.ComboBox(0, *options).model
def combo_changed(item_model: ui.AbstractItemModel, item: ui.AbstractItem):
value_model = item_model.get_item_value_model(item)
current_index = value_model.as_int
option = options[current_index]
print(f"Selected '{option}' at index {current_index}.")
combo_sub = combo_model.subscribe_item_changed_fn(combo_changed)
def clicked():
value_model = combo_model.get_item_value_model()
current_index = value_model.as_int
option = options[current_index]
print(f"Button Clicked! Selected '{option}' at index {current_index}.")
ui.Button("Print Combo Selection", clicked_fn=clicked)
| 1,009 | Python | 35.071427 | 83 | 0.634291 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/scripts/use_tokens.py | # SPDX-License-Identifier: Apache-2.0
# https://docs.omniverse.nvidia.com/py/kit/docs/guide/tokens.html
import carb.tokens
from pathlib import Path
path = Path("${shared_documents}") / "maticodes.foo"
resolved_path = carb.tokens.get_tokens_interface().resolve(str(path))
print(resolved_path) | 293 | Python | 31.666663 | 69 | 0.761092 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/scripts/simple_instancer.py | # SPDX-License-Identifier: Apache-2.0
import omni.usd
from pxr import Usd, UsdGeom, Sdf, Gf
stage: Usd.Stage = omni.usd.get_context().get_stage()
prim_path = Sdf.Path("/World/MyInstancer")
instancer: UsdGeom.PointInstancer = UsdGeom.PointInstancer.Define(stage, prim_path)
proto_container = UsdGeom.Scope.Define(stage, prim_path.AppendPath("Prototypes"))
shapes = []
shapes.append(UsdGeom.Cube.Define(stage, proto_container.GetPath().AppendPath("Cube")))
shapes.append(UsdGeom.Sphere.Define(stage, proto_container.GetPath().AppendPath("Sphere")))
shapes.append(UsdGeom.Cone.Define(stage, proto_container.GetPath().AppendPath("Cone")))
instancer.CreatePositionsAttr([Gf.Vec3f(0, 0, 0), Gf.Vec3f(2, 0, 0), Gf.Vec3f(4, 0, 0)])
instancer.CreatePrototypesRel().SetTargets([shape.GetPath() for shape in shapes])
instancer.CreateProtoIndicesAttr([0, 1, 2]) | 852 | Python | 49.176468 | 91 | 0.761737 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/scripts/one_widget_in_container.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():
with ui.CollapsableFrame():
with ui.VStack():
ui.FloatField()
ui.FloatField()
ui.Button("Button 1") | 328 | Python | 24.30769 | 62 | 0.588415 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/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-23: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2022-09-23"
# 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_23".
[[python.module]]
name = "maticodes.doh_2022_09_23"
| 784 | TOML | 26.068965 | 113 | 0.732143 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/docs/README.md | # Developer Office Hour - 09/23/2022
This is the sample code from the Developer Office Hour held on 09/23/2022, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- How do I query the selected item in a ui.ComboBox?
- How do I use Kit tokens?
- Why do I only see one widget in my UI container?
| 378 | Markdown | 41.111107 | 114 | 0.761905 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_09/maticodes/doh_2022_09_09/extension.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.ext
import omni.kit.commands
import omni.ui as ui
import omni.usd
from pxr import Gf, Sdf
# Check out: USDColorModel
# C:\ext_projects\omni-dev-office-hours\app\kit\exts\omni.example.ui\omni\example\ui\scripts\colorwidget_doc.py
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self._color_model = None
self._color_changed_subs = []
self._path_model = None
self._change_info_path_subscription = None
self._path_changed_sub = None
self._stage = omni.usd.get_context().get_stage()
self.frame.set_build_fn(self._build_window)
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("Property Path")
self._path_model = ui.StringField().model
self._path_changed_sub = self._path_model.subscribe_value_changed_fn(
self._on_path_changed
)
ui.Label("Color")
with ui.HStack(spacing=5):
self._color_model = ui.ColorWidget(width=0, height=0).model
for item in self._color_model.get_item_children():
component = self._color_model.get_item_value_model(item)
self._color_changed_subs.append(component.subscribe_value_changed_fn(self._on_color_changed))
ui.FloatField(component)
def _on_mtl_attr_changed(self, path):
color_attr = self._stage.GetAttributeAtPath(path)
color_model_items = self._color_model.get_item_children()
if color_attr:
color = color_attr.Get()
for i in range(len(color)):
component = self._color_model.get_item_value_model(color_model_items[i])
component.set_value(color[i])
def _on_path_changed(self, model):
if Sdf.Path.IsValidPathString(model.as_string):
attr_path = Sdf.Path(model.as_string)
color_attr = self._stage.GetAttributeAtPath(attr_path)
if color_attr:
self._change_info_path_subscription = omni.usd.get_watcher().subscribe_to_change_info_path(
attr_path,
self._on_mtl_attr_changed
)
def _on_color_changed(self, model):
values = []
for item in self._color_model.get_item_children():
component = self._color_model.get_item_value_model(item)
values.append(component.as_float)
if Sdf.Path.IsValidPathString(self._path_model.as_string):
attr_path = Sdf.Path(self._path_model.as_string)
color_attr = self._stage.GetAttributeAtPath(attr_path)
if color_attr:
color_attr.Set(Gf.Vec3f(*values[0:3]))
def destroy(self) -> None:
self._change_info_path_subscription = None
self._color_changed_subs = None
self._path_changed_sub = None
return super().destroy()
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2022_09_09] Dev Office Hours Extension (2022-09-09) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2022_09_09] Dev Office Hours Extension (2022-09-09) shutdown")
if self._window:
self._window.destroy()
self._window = None
| 3,584 | Python | 39.738636 | 117 | 0.588728 |