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 / maya_get_all_zero_normals.py
Last active January 20, 2023 15:01
In maya get all zero or near zero face vertex normals of a mesh using Python
import maya.api.OpenMaya as om
from maya import cmds
def get_dag_path(name):
"""Return MDagPath from object name"""
sel = om.MSelectionList()
sel.add(name)
return sel.getDagPath(0)
@BigRoy
BigRoy / maya_shift_keys_on_export.py
Created January 13, 2023 15:40
Maya Python code example on how to shift animation keys for an export
from maya import cmds
import contextlib
@contextlib.contextmanager
def offsetted_keys(offset, nodes=None):
if nodes is None:
# Apply to all time-based animation curves (excluding driven keys)
nodes = cmds.ls(type=("animCurveTL","animCurveTU","animCurveTA","animCurveTT"))
try:
@BigRoy
BigRoy / openpype_substancepainter_python_script_editor_plugin.py
Created January 12, 2023 15:57
Simple quick and dirty Substance Painter Plug-in which adds a Python Script Editor using OpenPype's scripting console
from PySide2 import QtCore, QtWidgets
import substance_painter.ui
try:
from openpype_modules.python_console_interpreter.window import PythonInterpreterWidget # noqa
except ModuleNotFoundError:
from openpype.modules.python_console_interpreter.window import PythonInterpreterWidget # noqa
WIDGET = None
ACTION = None
@BigRoy
BigRoy / substance_painter_get_project_export_data.py
Last active April 26, 2023 06:32
Get the export settings from Substance Painter project to find the export color spaces configured for the project
"""Substance Painter OCIO management
Adobe Substance 3D Painter supports OCIO color management using a per project
configuration. Output color spaces are defined at the project level
More information see:
- https://substance3d.adobe.com/documentation/spdoc/color-management-223053233.html # noqa
- https://substance3d.adobe.com/documentation/spdoc/color-management-with-opencolorio-225969419.html # noqa
"""
@BigRoy
BigRoy / substance_painter_get_export_maps.py
Created January 11, 2023 17:23
Get Adobe Substance 3D Painter export maps from an export preset by filename template to filename
import substance_painter.resource
import substance_painter.js
import tempfile
def get_export_maps(preset, folder=None, format="exr"):
"""Return filenames from export preset by filename template.
Note: This doesn't return each individual UV tile.
@BigRoy
BigRoy / substance_painter_export_dialog_scrape_formats.py
Created January 9, 2023 23:48
Scrape the export formats labels + internal urls from the Substance Painter Export dialog
import json
from PySide2 import QtCore, QtWidgets
import substance_painter.js
def scrape_export_presets():
app = QtWidgets.QApplication.instance()
# Allow app to catch up
app.processEvents()
@BigRoy
BigRoy / substancepainter_stylesheet.css
Created January 6, 2023 01:39
Substance Painter 8.2.0 QtWidgets.QApplication.instance().styleSheet()
QWidget { font-size: 11px; background-color: #333333; color: #cccccc;}
QWidget:disabled { color: #666666;}
QFrame, QDialog, QWindow { background: #333333;}
QFrame { border: none;}
QFrame[indentBorder=true] { margin-left: 2px; border-color: transparent; border-style: solid; border-left-width: 2px; padding: 4px 0px 4px 8px;}
QToolTip { color: #cccccc; background-color: #333333; padding: 4px; border: 1px solid #666666;}
QLabel { background: transparent;}
QLabel[messageHovered="true"] { text-decoration: underline;}
QLabel[messageType="warning"] { color: #ffb91a;}
QLabel[messageType="error"] { color: #ef4e35;}
@BigRoy
BigRoy / maya_print_optionvars.py
Created January 4, 2023 11:48
Maya print all option vars in sorted manner (just because I'm lazy)
from maya import cmds
STR_VALUE_SINGLE_LINE = True
for var in sorted(cmds.optionVar(list=True)):
value = cmds.optionVar(query=var)
if isinstance(value, str) and STR_VALUE_SINGLE_LINE:
value = value.replace("\n", " ")
@BigRoy
BigRoy / fusion_python_frame_flowview_to_selected.py
Created December 16, 2022 19:01
Example of how to frame the FlowView to all tools, selected tools or specified tools using Python (tested in Fusion 18.1.1 Build 7)
def get_correct_position(tool):
"""Get position of a tool that is usable for FlowView positions"""
result = tool.SaveSettings()
for tool in result["Tools"].values():
pos = tool["ViewInfo"]["Pos"]
return pos[1], pos[2]