Skip to content

Instantly share code, notes, and snippets.

View BigRoy's full-sized avatar

Roy Nieterau BigRoy

View GitHub Profile
@BigRoy
BigRoy / maya_sample_ramp_attribute.py
Last active March 30, 2023 08:01
Maya: Export ramp attribute samples to JSON. Sample multiple times along the ramp curve for its value.
import maya.cmds as cmds
import maya.api.OpenMaya as om
import json
def get_ramp_attribute(attr):
"""Return MRampAttribute for attribute name."""
sel = om.MSelectionList()
sel.add(parm)
plug = sel.getPlug(0)
@BigRoy
BigRoy / openrv_find_annotated_frames.py
Last active April 18, 2023 13:16
OpenRV Python find annotated frames including those made in sequence group views
import rv
def get_source_frame(frame, root, source):
source_types = {"RVImageSource", "RVFileSource"}
# Find the frame for `source` at `frame` when viewing `root`
for info in rv.commands.metaEvaluate(frame, root):
if info["node"] == source:
return info["frame"]
@BigRoy
BigRoy / openpype_query_representation_from_filepath.py
Created May 17, 2023 11:29
OpenPype v3 query the representations from a published file path
from openpype.pipeline import legacy_io, Anatomy
path = r"/path/to/representation/file.abc"
anatomy = Anatomy()
success, rootless_path = anatomy.find_root_template_from_path(path)
assert success
for result in legacy_io.find({"files.path": rootless_path, "type": "representation"}):
print(result)
@BigRoy
BigRoy / delete_list_of_components_on_selection.py
Created May 22, 2023 08:52
In Maya how to quickly delete the same components on multiple objects through Python. (Got asked this by a friend)
# Delete all components in the `components` list from the selected nodes
from maya import cmds
components = [
".f[4096]",
".f[3005:3055"],
# etc.
]
@BigRoy
BigRoy / maya_optimize_passthrough_connections.py
Last active August 1, 2023 04:14
Maya passthrough any a->b->c attribute connections changing it to a direct a->c connection
from maya import cmds
from collections import defaultdict
import contextlib
@contextlib.contextmanager
def unlocked(plug):
"""Unlock attribute during the context"""
locked = cmds.getAttr(plug, lock=True)
if locked:
@BigRoy
BigRoy / openpype_list_workfiles_published_from.py
Created August 11, 2023 13:35
OpenPype list all workfiles from a folder that were involved in a publish (= list all workfiles that were published from)
# Return all source workfile paths in a workfile folder that were involved in a publish
import re
from openpype.pipeline import legacy_io, Anatomy
from openpype.pipeline.context_tools import get_current_project_name
project_name = get_current_project_name()
anatomy = Anatomy(project_name)
folder = r"path/to/workfiles/folder
success, folder = anatomy.find_root_template_from_path(folder)
files_in_folder_query = re.escape(folder) + "/[^/]+"
@BigRoy
BigRoy / fusion_save_active_view_image.py
Last active October 13, 2024 03:29
Blackmagic Design Fusion save image from active comp view
import itertools
def iter_viewers(comp):
"""Iterate GLPreview views for Composition.
It prefers the active view first, then yields views
from the current frame (active window), then from the comp,
then from floating views last.
@BigRoy
BigRoy / maya_query_holes_mesh.py
Created August 24, 2023 20:09
Maya find meshes with holes in them (that are not watertight) by checking if any edge is a boundary edge (not connected to two faces)
import maya.api.OpenMaya as om
from maya import cmds
def has_boundaries(mesh):
sel = om.MSelectionList()
sel.add(mesh)
dag = sel.getDagPath(0)
it = om.MItMeshEdge(dag)
while not it.isDone():
@BigRoy
BigRoy / usd_list_layer_edits_editor.py
Last active November 7, 2024 15:42
Quick and dirty "List USD Layer Edits" to allow removal of Sdf.PrimSpec, Sdf.PropertySpec, Sdf.AttributeSpec, Sdf.RelationshipSpec through a Python Qt interface
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 / hou_set_node_thumbnail.py
Created September 27, 2023 09:29
Houdini set node image thumbnail (NetworkView background image) and attach / link it to the node through Python
import hou
import contextlib
@contextlib.contextmanager
def editor_at_node(node, pane_tab_type=hou.paneTabType.NetworkEditor):
editor = hou.ui.paneTabOfType(pane_tab_type)
original_pwd = editor.pwd()
try: