Skip to content

Instantly share code, notes, and snippets.

View rondreas's full-sized avatar

Andreas Rånman rondreas

View GitHub Profile
@rondreas
rondreas / dictListFilter.py
Created March 8, 2016 12:53
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
rondreas / checksum.py
Last active September 24, 2019 15:45
#!/usr/bin/python3
import hashlib, sys
"""
Command line tool to get checksums in python.
Supply filepath for file to process, and which hash
method to use.
"""
@rondreas
rondreas / read_json_example.py
Created January 6, 2017 12:03
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
rondreas / forEachConstrain.py
Last active March 23, 2017 15:48
constrain all _fk joints to respective _bn assuming root_bn exists.
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 September 10, 2017 11:14
Batch export UVs for all selected objects.
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)
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()
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 October 16, 2017 09:58
Maya defaultRenderGlobals imageFormats
{
"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 November 14, 2017 16:32
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 = pm.ls(type="shape")
output = list()
for shape in shapes:
if shape.nodeName() != shape.getParent().nodeName()+'Shape':
@rondreas
rondreas / toolToggle.py
Last active February 13, 2018 10:14
Hotkey overlay to toggle modes in Maya,
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