Skip to content

Instantly share code, notes, and snippets.

from PySide2 import QtCore, QtGui, QtWidgets
from maya import OpenMayaUI as omui
from shiboken2 import wrapInstance
class ClosingWindow(QtGui.QWindow):
def eventFilter(self, object, event):
# Prevent this window from being closed. It should stay alive until Maya exits.
if object is self and event.type() == QtCore.QEvent.Close:
return True
import pymel.core as pm
from zMayaTools import maya_helpers
# Imported skeletons often have ugly scaling. We should be able to just turn on move skinned
# joints and freeze transforms, but Maya tries to be helpful and prevents us from doing this.
def get_descendants_depth_first(node, depth=0):
if not isinstance(node, pm.nodetypes.Transform):
yield node, depth
zewt / gist:73bd5f83927f3ccf20c32cf0440120a4
Created August 19, 2020 06:14
Reset bind position to joint position
# Public domain
from pymel import core as pm
import re
def resetJointOnCluster(joint, skinClusterPreMatrixPlug):
inverseMatrix = joint.attr('worldInverseMatrix').get()
curMatrix = skinClusterPreMatrixPlug.get()
if curMatrix is not None:
different = any(abs(a-b) > 0.00001 for a, b in zip(inverseMatrix, curMatrix))
zewt / gist:7090ed6aa800109b8019e596280406ac
Created August 19, 2020 06:14
Set joints to bind position
# Public domain
import pymel.core as pm
from pymel import core as pm
from maya.api import OpenMaya as om
def getSkinClusterConnection(node):
for conn in pm.listConnections(node.attr('worldMatrix'), d=True, s=False, p=True, type='skinCluster') or []:
skinCluster = conn.node()
idx = conn.index()
namespace std
// Compare two MObjects. This allows them to be used as keys in std::map.
struct less<MObject>
size_t operator()(const MObject &lhs, const MObject &rhs) const;
// A hash for MObject. This allows them to be used as keys in std::unordered_map.
zewt / gist:4f5e54d20839697c94df0afbf67e41a9
Created April 3, 2018 04:02
Aborted Maya pick walking script
import sys
import pymel.core as pm
def pick_walk(direction, add=False):
nodes =
new_nodes = []
non_dag_nodes = []
for node in nodes:
# Make a list of non-DAG nodes.
if not isinstance(node, pm.nodetypes.DagNode):
zewt / gist:b4829c63500de72682785dc40a9cb4c6
Created December 20, 2017 21:40
Remap animation sources in Maya's time editor
import pymel.core as pm
def remap_clip(clip_name, new_anim_source):
clip_id = pm.timeEditorClip(clip_name, q=True, clipIdFromNodeName=True)
print 'Remapping clip:', clip_name
sources = pm.timeEditorClip(clip_id, q=True, remappedSourceAttrs=True)
source_indices, source_paths = sources[0::2], sources[1::2]
# targets = pm.timeEditorClip(clip_id, q=True, remappedTargetAttrs=True)
zewt / gist:5323bbf8f46ef161b20601c75052948a
Created December 6, 2017 02:14
Python script to give 10000 Eden tokens in Binding of Isaac
# This gives 10000 Eden tokens.
import struct
CrcTable = [ 0x00000000L, 0x09073096L, 0x120E612CL, 0x1B0951BAL, 0xFF6DC419L, 0xF66AF48FL, 0xED63A535L, 0xE46495A3L, 0xFEDB8832L, 0xF7DCB8A4L, 0xECD5E91EL, 0xE5D2D988L, 0x01B64C2BL, 0x08B17CBDL, 0x13B82D07L, 0x1ABF1D91L, 0xFDB71064L, 0xF4B020F2L, 0xEFB97148L, 0xE6BE41DEL, 0x02DAD47DL, 0x0BDDE4EBL, 0x10D4B551L, 0x19D385C7L, 0x036C9856L, 0x0A6BA8C0L, 0x1162F97AL, 0x1865C9ECL, 0xFC015C4FL, 0xF5066CD9L, 0xEE0F3D63L, 0xE7080DF5L, 0xFB6E20C8L, 0xF269105EL, 0xE96041E4L, 0xE0677172L, 0x0403E4D1L, 0x0D04D447L, 0x160D85FDL, 0x1F0AB56BL, 0x05B5A8FAL, 0x0CB2986CL, 0x17BBC9D6L, 0x1EBCF940L, 0xFAD86CE3L, 0xF3DF5C75L, 0xE8D60DCFL, 0xE1D13D59L, 0x06D930ACL, 0x0FDE003AL, 0x14D75180L, 0x1DD06116L, 0xF9B4F4B5L, 0xF0B3C423L, 0xEBBA9599L, 0xE2BDA50FL, 0xF802B89EL, 0xF1058808L, 0xEA0CD9B2L, 0xE30BE924L, 0x076F7C87L, 0x0E684C11L, 0x15611DABL, 0x1C662D3DL, 0xF6DC4190L, 0xFFDB7106L, 0xE4D220BCL, 0xEDD5102AL, 0x09B18589L, 0x00B6B51FL, 0x1BBFE4A5L, 0x12B8D433L, 0x0807C9A2L, 0x0100F934L, 0
zewt / gist:f8d8d90b70bd406ea71250d4db5713bd
Created December 3, 2017 21:15
Flatten your conditionals
Don't nest conditionals when you can return. Don't do this:
int do_task()
// Success. Do lots of stuff with the data.
// (insert 30 lines of code here)
return n;
} else {