Skip to content

Instantly share code, notes, and snippets.

View BigRoy's full-sized avatar

Roy Nieterau BigRoy

View GitHub Profile
@BigRoy
BigRoy / maya_query_mesh_uv_udim_tiles.py
Last active March 21, 2024 06:18
Query the used UDIM tiles for the UVs of an input mesh
from maya import cmds
def get_bounding_box_tiles(bb):
u_minmax, v_minmax = bb
# If the max is exactly on the integer boundary we allow it to be
# part of the tile of the previos integer so we can subtract one.
# But since we'll need to add one to iterate "up to" the maximum for
# the `range` function we will instead add one to the opposite cases.
@BigRoy
BigRoy / maya_query_attribute_api_properties_and_affects.py
Created February 22, 2021 11:38
For a given 'node' and 'attr' print API properties and it's "attributeAffects" for the attribute - for inspecting/debugging attributes from existing nodes.
import maya.api.OpenMaya as om
node = "myNode"
attr = "myAttribute"
sel = om.MSelectionList()
sel.add(node)
fn_dep = om.MFnDependencyNode(sel.getDependNode(0))
o_attr = fn_dep.attribute(attr)
fn_attr = om.MFnAttribute(o_attr)
@BigRoy
BigRoy / maya_reset_lattice_tweaks_by_percentage.py
Last active April 9, 2021 11:29
Maya - Reset lattice tweaks on selected lattice points by a percentage (quick 'n' dirty script)
import itertools
import maya.api.OpenMaya as om
from maya import cmds
def grouper(iterable, n, fillvalue=None):
"""Collect data into fixed-length chunks or blocks
Examples:
grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx
@BigRoy
BigRoy / maya_vrayproxy_assign_shaders_avalon.py
Created April 23, 2021 12:13
Assign Avalon/Colorbleed-config published looks on VRayProxy nodes that load Alembic files.
import os
from collections import defaultdict
import logging
import alembic.Abc
import json
from maya import cmds
import colorbleed.maya.lib as lib
import avalon.io as io
import avalon.maya
@BigRoy
BigRoy / get_maya_outliner_icons.py
Last active June 7, 2021 22:09
Example of how to cache Maya outliner (and other maya resources) icons to use in a Qt widget or view.
import os
from maya import cmds
from PySide2 import QtWidgets, QtGui, QtCore
class IconCache(object):
"""Simple Icon cache for Maya resources"""
def __init__(self):
self._paths_cache = {}
@BigRoy
BigRoy / get_vray_render_element_attributes.py
Created June 16, 2021 13:10
Get custom attributes for each VRayRenderElement class type using vray "getAHint" similar to how V-Ray MEL procedure 'vrayAddRenderElementImpl' does it.
from maya import cmds
import itertools
def get_render_element_attributes(name):
"""Get attributes for VRayRenderElement based on class type"""
attrs = []
for i in itertools.count():
buffer = cmds.vray("getAHint",
"RenderElement",
@BigRoy
BigRoy / maya_what_is_mel_code.py
Created June 17, 2021 11:15
Return location of MEL script using maya whatIs plus directly print the source code of the procedure
from maya import cmds
import re
import os
def get_mel_script_code(name):
"""Return source code of the MEL procedure loaded from a .mel script file"""
result = mel.eval('whatIs("%s")' % name)
if result == "Unknown":
@BigRoy
BigRoy / maya_get_reference_edits_string_bug.py
Last active June 18, 2021 09:18
Maya 2020 reproducable case of reference edits for string attributes stripping whitespaces in a string value
from maya import cmds, mel
import maya.OpenMaya as om
# Point filepath to a mayaAscii file that has at least one transform node in it
filepath = r"path/to/maya_scene_to_reference.ma"
# Reference the file
nodes = cmds.file(filepath, reference=True, type="mayaAscii", ignoreVersion=True, gl=True, mergeNamespacesOnClash=True, namespace="camera", options="v=0;", returnNewNodes=True)
ref = cmds.ls(nodes, type="reference")[0]
@BigRoy
BigRoy / maya_query_and_set_playblast_display_option_vars.py
Created August 6, 2021 12:50
Maya Playblast Option Vars for "Playblast Display" options for viewport and some examples
from maya import cmds
# List all optionVars starting with "playblast"
# The ones for the Playblast Display start with "playblastShow"
# And the "playblastOverrideViewport" enables/disables them all together
vars = sorted([var for var in cmds.optionVar(list=True) if var.startswith("playblast")])
for var in vars:
print var
@BigRoy
BigRoy / openpype_utils.md
Last active January 12, 2022 12:02
Tips & Tricks for OpenPype

How to make a publish plug-in manageable in Studio Settings?

  1. Edit the related schema. For example: openpype\settings\entities\schemas\projects_schema\schemas\schema_maya_publish.json
  2. Run run_settings script
  3. Save the defaults.
  4. Re-run tray.

For example this could be added to make it possible to disable the ExtractModel plug-in

 {