Skip to content

Instantly share code, notes, and snippets.

Avatar

Andreas Rånman rondreas

View GitHub Profile
@rondreas
rondreas / dictListFilter.py
Created Mar 8, 2016
Filter Dictionary List
View dictListFilter.py
#!/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
rondreas / read_json_example.py
Created Jan 6, 2017
Load and print json file
View read_json_example.py
import json
with open(filePath, 'r') as fp:
j = json.load(fp)
print(json.dumps(j, sort_keys=True, indent=2))
@rondreas
rondreas / forEachConstrain.py
Last active Mar 23, 2017
constrain all _fk joints to respective _bn assuming root_bn exists.
View forEachConstrain.py
import maya.cmds as cmds
# select all joints _bn
cmds.select('root_bn', hierarchy=True)
# For each _fk constrain to _bn
for bn in cmds.ls(selection=True):
try:
cmds.orientConstraint( bn.replace('_bn', '_fk'), bn )
cmds.pointConstraint( bn.replace('_bn', '_fk'), bn )
@rondreas
rondreas / batchUVSnapshot.py
Created Sep 10, 2017
Batch export UVs for all selected objects.
View batchUVSnapshot.py
import maya.cmds as cmds
def batchUVSnapshot(fp, resolution, fileType):
# List all selected items
items = cmds.ls( selection = True, long = True )
for item in items:
cmds.select( item, replace = True)
View flattenAlongPlane.py
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))
View hs_unfold.py
import pymel.core as pm
import maya.mel as mel
# Get current selection
selected = pm.selected()
mel.eval("ConvertSelectionToUVs")
# Unfold, straighten, unfold
pm.u3dUnfold(selected, ite = 1, p = 0, bi = 1, tf = 1, ms = 1024, rs = 0)
@rondreas
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
rondreas / bad_shapes.py
Created Nov 14, 2017
Get all shape nodes which deviates from Maya standard shape naming convention.
View bad_shapes.py
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 = pm.ls(type="shape")
output = list()
for shape in shapes:
if shape.nodeName() != shape.getParent().nodeName()+'Shape':
@rondreas
rondreas / toolToggle.py
Last active Feb 13, 2018
Hotkey overlay to toggle modes in Maya,
View toolToggle.py
import pymel.core as pm
from functools import partial
from maya import OpenMayaUI as omui
try:
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from shiboken2 import wrapInstance
@rondreas
rondreas / cutHardEdges.py
Created Feb 13, 2018
Cut Hard Edges on selected object
View cutHardEdges.py
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()]
pm.polyMapCut(hard_edges)