Skip to content

Instantly share code, notes, and snippets.

Avatar

Roy Nieterau BigRoy

View GitHub Profile
@BigRoy
BigRoy / maya_cycle_evaluation_error.py
Created Jan 12, 2022
Maya check Cycle Errors more thoroughly where maya.cmds.cycleCheck(list=True) fails.
View maya_cycle_evaluation_error.py
from maya import cmds
import contextlib
@contextlib.contextmanager
def capture_cycle_errors():
"""Capture the plugs in Cycle Error warnings.
During this context "Cycle on 'x' may not evaluate as expected"
are captured and 'x' is extracted as plugs in the yielded list.
@BigRoy
BigRoy / openpype_utils.md
Last active Jan 12, 2022
Tips & Tricks for OpenPype
View openpype_utils.md

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

 {
@BigRoy
BigRoy / maya_query_and_set_playblast_display_option_vars.py
Created Aug 6, 2021
Maya Playblast Option Vars for "Playblast Display" options for viewport and some examples
View maya_query_and_set_playblast_display_option_vars.py
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 / 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)