Skip to content

Instantly share code, notes, and snippets.

Avatar

Roy Nieterau BigRoy

View GitHub Profile
@BigRoy
BigRoy / maya_get_reference_edits_string_bug.py
Last active Jun 18, 2021
Maya 2020 reproducable case of reference edits for string attributes stripping whitespaces in a string value
View maya_get_reference_edits_string_bug.py
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_what_is_mel_code.py
Created Jun 17, 2021
Return location of MEL script using maya whatIs plus directly print the source code of the procedure
View maya_what_is_mel_code.py
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 / get_vray_render_element_attributes.py
Created Jun 16, 2021
Get custom attributes for each VRayRenderElement class type using vray "getAHint" similar to how V-Ray MEL procedure 'vrayAddRenderElementImpl' does it.
View get_vray_render_element_attributes.py
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 / get_maya_outliner_icons.py
Last active Jun 7, 2021
Example of how to cache Maya outliner (and other maya resources) icons to use in a Qt widget or view.
View get_maya_outliner_icons.py
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 / maya_vrayproxy_assign_shaders_avalon.py
Created Apr 23, 2021
Assign Avalon/Colorbleed-config published looks on VRayProxy nodes that load Alembic files.
View maya_vrayproxy_assign_shaders_avalon.py
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 / maya_reset_lattice_tweaks_by_percentage.py
Last active Apr 9, 2021
Maya - Reset lattice tweaks on selected lattice points by a percentage (quick 'n' dirty script)
View maya_reset_lattice_tweaks_by_percentage.py
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_query_attribute_api_properties_and_affects.py
Created Feb 22, 2021
For a given 'node' and 'attr' print API properties and it's "attributeAffects" for the attribute - for inspecting/debugging attributes from existing nodes.
View maya_query_attribute_api_properties_and_affects.py
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_query_mesh_uv_udim_tiles.py
Last active Mar 3, 2021
Query the used UDIM tiles for the UVs of an input mesh
View maya_query_mesh_uv_udim_tiles.py
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 / avalon_load_by_cbid.py
Created Feb 8, 2021
Avalon example for colorbleed-config on how to load latest version of an asset's `modelDefault` solely from the `cbId` attribute.
View avalon_load_by_cbid.py
# Example on how to load latest `modelDefault` of an asset by `cbId` value using `AbcLoader` (alembic)
import avalon.io as io
import avalon.api as api
from maya import cmds
node = "my_node"
cbid = cmds.getAttr("%s.cbId" % node)
# Get asset object id from cbId
object_id = cbid.split(":", 1)[0] # The part before the : is the asset id
@BigRoy
BigRoy / maya_export_nodes_from_render_setup_layer.py
Created Feb 3, 2021
Export Maya nodes from Render Setup layer as if flattened in that layer instead of exporting the defaultRenderLayer as Maya forces by default
View maya_export_nodes_from_render_setup_layer.py
import os
import contextlib
from maya import cmds
from maya.app.renderSetup.model import renderSetup
# Custom library functions, see: https://github.com/Colorbleed/colorbleed-config
from colorbleed.maya import lib
from colorbleed.lib import pairwise