Skip to content

Instantly share code, notes, and snippets.


Andreas Rånman rondreas

View GitHub Profile
rondreas /
Created Mar 8, 2016
Filter Dictionary List
#!/usr/bin/env python3
def filter(listInput, **kwargs):
''' Searches list of dictionaries for matches to
all key value pairs expressed as key='value' '''
sortedList = []
for dictionary in listInput:
matches = 0
rondreas /
Created Jan 6, 2017
Load and print json file
import json
with open(filePath, 'r') as fp:
j = json.load(fp)
print(json.dumps(j, sort_keys=True, indent=2))
rondreas /
Last active Mar 23, 2017
constrain all _fk joints to respective _bn assuming root_bn exists.
import maya.cmds as cmds
# select all joints _bn'root_bn', hierarchy=True)
# For each _fk constrain to _bn
for bn in
cmds.orientConstraint( bn.replace('_bn', '_fk'), bn )
cmds.pointConstraint( bn.replace('_bn', '_fk'), bn )
rondreas /
Created Sep 10, 2017
Batch export UVs for all selected objects.
import maya.cmds as cmds
def batchUVSnapshot(fp, resolution, fileType):
# List all selected items
items = selection = True, long = True )
for item in items: item, replace = True)
import pymel.core as pymel
import maya.api.OpenMaya as om
def flattenAlongPlane(joints):
# Get worldspace position every joint but for first and last, and get their average position
vectors = [om.MVector(pymel.joint(x,q=True, p=True, a=True)) for x in joints[1:-1]]
avg = om.MPoint([sum(v)/len(vectors) for v in zip(*vectors)])
p1 = om.MPoint(pymel.joint(joints[0], q=True, p=True, a=True))
p2 = om.MPoint(pymel.joint(joints[-1], q=True, p=True, a=True))
import pymel.core as pm
import maya.mel as mel
# Get current selection
selected = pm.selected()
# Unfold, straighten, unfold
pm.u3dUnfold(selected, ite = 1, p = 0, bi = 1, tf = 1, ms = 1024, rs = 0)
rondreas / imageFormats.json
Created Oct 16, 2017
Maya defaultRenderGlobals imageFormats
View imageFormats.json
"AVI": 23,
"Alias PIX": 6,
"Cineon": 11,
"DDS": 35,
"EPS": 9,
"EXR(exr)": 40,
"GIF": 0,
"JPEG": 8,
"MacPaint": 30,
rondreas /
Created Nov 14, 2017
Get all shape nodes which deviates from Maya standard shape naming convention.
import pymel.core as pm
def find_bad_shapes():
""" Find and select all shapes which has not inherited their names from their parent transform,
such as transformShape. """
shapes ="shape")
output = list()
for shape in shapes:
if shape.nodeName() != shape.getParent().nodeName()+'Shape':
rondreas /
Last active Feb 13, 2018
Hotkey overlay to toggle modes in Maya,
import pymel.core as pm
from functools import partial
from maya import OpenMayaUI as omui
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from shiboken2 import wrapInstance
rondreas /
Created Feb 13, 2018
Cut Hard Edges on selected object
import pymel.core as pm
# Get all non smooth edges, and cut their UVs
hard_edges = [e for e in pm.selected()[0].e if not e.isSmooth()]