Skip to content

Instantly share code, notes, and snippets.

View BigRoy's full-sized avatar

Roy Nieterau BigRoy

View GitHub Profile
BigRoy /
Created November 28, 2023 12:15
USD Python API import layer into an existing layer at given path
from 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 /
Created November 23, 2023 16:15
USD simple print diff of dirty layer in memory to the original state on disk.
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 /
Created November 19, 2023 22:59
Get all registered prim types to create by a nice plug-in grouping
from pxr import Usd, Plug, Tf
from collections import defaultdict
"usdGeom": "Geometry",
"usdLux": "Lighting",
"mayaUsd_Schemas": "Maya Reference",
"usdMedia": "Media",
"usdRender": "Render",
"usdRi": "RenderMan",
BigRoy /
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
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 /
Created November 13, 2023 13:33
Example AYON / OpenPype PreLaunchHook to insert Ayon's FFMPEG to PATH environment variable on launch of applications
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 /
Created November 8, 2023 19:30
OpenPype Extractor Mixin
class ExtractorMixin:
"""OpenPype Extractor helper methods"""
def add_representation(self, instance, name,
files, staging_dir, ext=None,
BigRoy /
Created November 3, 2023 11:08
Houdini Python LOPs node add simple 360 Y-axis rotation on a prim
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")
BigRoy /
Last active October 25, 2023 21:07
Houdini attach nodes to each other - make one follow the other
import hou
import json
class Attachments:
user_data_key = "attachednodes"
def attach_node(node, node_to_follow):
BigRoy /
Created October 25, 2023 12:40
OpenPype get thumbnail for an entity
from openpype.pipeline.thumbnail import get_thumbnail_binary
from openpype.client import get_thumbnail_id_from_source, get_thumbnail
def get_entity_thumbnail(project_name, entity_id, entity_type):
thumbnail_id = get_thumbnail_id_from_source(project_name, entity_type, entity_id)
if not thumbnail_id:
thumbnail_entity = get_thumbnail(project_name, thumbnail_id, entity_type, entity_id)
if not thumbnail_entity:
BigRoy /
Created October 19, 2023 13:45
Maya USD Import Chaser in Python to import `primvars:cbId_transform` attribute to the transform as `cbId` instead of as attribute on the shape
import logging
import mayaUsd.lib as mayaUsdLib
from maya import cmds
import maya.api.OpenMaya as OpenMaya
def create_cbid_attr(default_value):
default = OpenMaya.MFnStringData().create(default_value)
return OpenMaya.MFnTypedAttribute().create("cbId",