Skip to content

Instantly share code, notes, and snippets.

View BigRoy's full-sized avatar

Roy Nieterau BigRoy

View GitHub Profile
@BigRoy
BigRoy / maya_usd_light_link_basic_ui.py
Last active December 5, 2023 23:11
Quick and dirty example functions/UI to light link with USD in Python for Maya
View maya_usd_light_link_basic_ui.py
@BigRoy
BigRoy / usd_list_layer_edits_editor.py
Last active November 30, 2023 13:52
Quick and dirty "List USD Layer Edits" to allow removal of Sdf.PrimSpec, Sdf.PropertySpec, Sdf.AttributeSpec, Sdf.RelationshipSpec through a Python Qt interface
View usd_list_layer_edits_editor.py
from PySide2 import QtCore, QtWidgets, QtGui
from pxr import Usd, Tf, Sdf
# See: https://github.com/PixarAnimationStudios/OpenUSD/blob/release/pxr/usd/sdf/fileIO_Common.cpp#L879-L892
SPECIFIER_LABEL = {
Sdf.SpecifierDef: "def",
Sdf.SpecifierOver: "over",
Sdf.SpecifierClass: "abstract"
}
@BigRoy
BigRoy / usd_import_layer.py
Created November 28, 2023 12:15
USD Python API import layer into an existing layer at given path
View usd_import_layer.py
from collections.abc import Callable
from pxr import Sdf
def import_layer(
path: str,
target_layer: Sdf.Layer,
target_path: Sdf.Path,
copy_spec_fn: Callable[[Sdf.Layer, Sdf.Path, Sdf.Layer, Sdf.Path], bool] = Sdf.CopySpec
):
@BigRoy
BigRoy / usd_print_simple_diff_to_layer_on_disk.py
Created November 23, 2023 16:15
USD simple print diff of dirty layer in memory to the original state on disk.
View usd_print_simple_diff_to_layer_on_disk.py
import difflib
from pxr import Sdf
# Purely as an example, say this `layer` is one that's currently already
# available and is dirty currently
identifier = r"C:\Users\User\Desktop\asset.usd"
layer = Sdf.Layer.FindOrOpen(identifier)
layer.Reload() # just so we can re-run this script
layer.subLayerPaths.append("./hello_world.usd") # making a change, making it dirty
@BigRoy
BigRoy / usdviewport_qt.py
Last active November 20, 2023 09:53
Example of how to embed a simple USD viewport in Qt application
View usdviewport_qt.py
"""
MIT License
Copyright (c) 2019 Roy Nieterau
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@BigRoy
BigRoy / usd_get_registered_prim_type_schemas.py
Created November 19, 2023 22:59
Get all registered prim types to create by a nice plug-in grouping
View usd_get_registered_prim_type_schemas.py
from pxr import Usd, Plug, Tf
from collections import defaultdict
NICE_NAMES = {
"usdGeom": "Geometry",
"usdLux": "Lighting",
"mayaUsd_Schemas": "Maya Reference",
"usdMedia": "Media",
"usdRender": "Render",
"usdRi": "RenderMan",
@BigRoy
BigRoy / usd_sdf_move_prim_spec.py
Last active November 16, 2023 11:52
USD API move prim spec including repathing relationships and connections to it and its children in a single Sdf Layer
View usd_sdf_move_prim_spec.py
from pxr import Sdf, Usd
LIST_ATTRS = ['addedItems', 'appendedItems', 'deletedItems', 'explicitItems',
'orderedItems', 'prependedItems']
def repath_properties(layer, old_path, new_path):
"""Re-path property relationship targets and attribute connections.
This will replace any relationship or connections from old path
@BigRoy
BigRoy / ayon_insert_ffmpeg_path_prelaunchhook.py
Created November 13, 2023 13:33
Example AYON / OpenPype PreLaunchHook to insert Ayon's FFMPEG to PATH environment variable on launch of applications
View ayon_insert_ffmpeg_path_prelaunchhook.py
import os
from openpype.lib.applications import PreLaunchHook, LaunchTypes
from openpype.lib.vendor_bin_utils import get_ffmpeg_tool_path
class AddFFMPEGToPath(PreLaunchHook):
"""Insert Ayon FFMPEG in `PATH`"""
# Should be as last hook because must change launch arguments to string
app_groups = {"*"}
platforms = {"*"}
@BigRoy
BigRoy / openpype_extractor_mixin.py
Created November 8, 2023 19:30
OpenPype Extractor Mixin
View openpype_extractor_mixin.py
class ExtractorMixin:
"""OpenPype Extractor helper methods"""
def add_representation(self, instance, name,
files, staging_dir, ext=None,
output_name=None,
frame_start=None,
frame_end=None,
@BigRoy
BigRoy / houdini_lop_python_add_turntable_spin_anim.py
Created November 3, 2023 11:08
Houdini Python LOPs node add simple 360 Y-axis rotation on a prim
View houdini_lop_python_add_turntable_spin_anim.py
from pxr import UsdGeom, Usd
node = hou.pwd()
stage = node.editableStage()
path = "/cube"
prim = stage.GetPrimAtPath(path)
start = node.evalParm("start")
end = node.evalParm("end")