Skip to content

Instantly share code, notes, and snippets.

View BigRoy's full-sized avatar

Roy Nieterau BigRoy

View GitHub Profile
@BigRoy
BigRoy / mpxfiletranslator_crash_example.py
Created October 19, 2017 13:49
This is a custom MPxFileTranslator that can be loaded as plug-in into Maya. With this loaded as plug-in you can reference any `.txt` file on disk. To make this work save a `.ma` scene next to the text file with the same name and reference the txt file. What should happen is that the `.ma` should be loaded three times within a single reference no…
"""This is a custom MPxFileTranslator that can be loaded as plug-in into Maya.
With this loaded as plug-in you can reference any `.txt` file on disk.
To make this work save a `.ma` scene next to the text file with the same name
and reference the txt file. What should happen is that the `.ma` should be
loaded three times within a single reference node in Maya.
Note: it crashes in Maya 2018 when saving the scene and then reopening the scene.
"""
@BigRoy
BigRoy / qt_qcolumnview_selection.py
Created March 8, 2017 14:14
Set QColumnView selection (and update the columns)
import sys
import os
from Qt import QtWidgets, QtCore, QtGui
def main():
app = QtWidgets.QApplication(sys.argv)
path = r"C:\test\subfolder\file.txt"
@BigRoy
BigRoy / fusion_print_selected_tool_inputs.py
Last active July 25, 2016 20:44
Debug print selected tool inputs in Fusion
# For each selected tool
tools = comp.GetToolList(True).values()
for tool in tools:
print tool.Name
# For each input
inputs = tool.GetInputList().values()
for input in inputs:
name = input.Name # ui friendly name
@BigRoy
BigRoy / integrate_asset_simple.py
Created February 27, 2016 12:32
A Pyblish integrator draft for Pyblish Magenta that integrates files into a "publish" folder next to the current file.
import os
import shutil
import pyblish.api
import pyblish.util
import pyblish_magenta.api
class IntegrateAssetsSimple(pyblish.api.Integrator):
"""Name and position instances on disk for shots
@BigRoy
BigRoy / parse_mel_cmd.py
Last active October 12, 2021 13:11
Parse a Maya MEL command string into the command name, args and kwargs.
def parse_mel_cmd(melStr):
"""Return the command, args and kwargs for a MEL command string"""
# Get python variant and split of pymel import line
import pymel.tools.mel2py as mel2py
pyCmd = mel2py.mel2pyStr(melStr)
pyCmd = pyCmd.splitlines()[1]
cmd, arguments = pyCmd.split("(", 1)
@BigRoy
BigRoy / maya_extract_edits.py
Created January 20, 2016 15:28
Description of how one could retrieve the "edits" for referenced nodes (draft implementation)
"""This is a first draft template that could be used to retrieve the edits on referenced nodes that define a look
Next step would be to filter the edits of interest, like shader assignments, sets they are added to, attributes that were added or changed in value.
Then we need to store these changes in a format that is artist-friendly and can be re-applied in another scene.
"""
import maya.cmds as mc
from collections import defaultdict
@BigRoy
BigRoy / pyblish_get_family_options.py
Last active November 20, 2015 10:57
Get the options supported by a families' plug-ins by retrieving their "options" property and assembling them. The "options" property should be provided by the plug-in. For example this is done in Extractors in Pyblish Magenta: https://github.com/pyblish/pyblish-magenta
import pyblish.api
import logging
log = logging.getLogger(__name__)
def get_family_options(plugins, family):
"""Return the user-specifiable options for this family
The options name and types are gathered through
@BigRoy
BigRoy / inspect_file.py
Created October 27, 2015 10:56
Testing inspect filepath options for Pyblish plugins
cls.__path__ = None
if cls.__module__ != '__main__': # if not local (in-memory)
try:
cls.__path__ = inspect.getfile(cls)
except RuntimeError, e:
print e
import maya.cmds as mc
def offsets_to_input(mesh):
num_pts = mc.getAttr('{0}.pnts'.format(mesh), size=True)
for i in range(num_pts):
# Get the internal offset
offset = mc.getAttr('{0}.pnts[{1}]'.format(mesh, i))[0]
# Move the vertex position by the internal offset value (relative)
import maya.OpenMaya as om
import maya.cmds as mc
import uuid
def ensure_id(node):
"""Add a uuid attribute on the given node with a unique value.
Skips nodes that already have the attribute, unless when used upon duplicating.
Maya temporarily assigns the prefix '__PrenotatoPerDuplicare_' so we use that