Skip to content

Instantly share code, notes, and snippets.

View AndresMWeber's full-sized avatar
💭
Katas for Life!

Andres Weber AndresMWeber

💭
Katas for Life!
View GitHub Profile
@AndresMWeber
AndresMWeber / wrap_register.py
Last active March 10, 2017 22:45
Function wrap and Register example
class Registry(object):
pass
def register_wrapper(func):
print 'adding function %s to registry.' % func.__name__
setattr(Registry, func.__name__, classmethod(func))
return func
def wrapper(**kwargs_outer):
print 'in outside wrapper with kwargs', kwargs_outer
@AndresMWeber
AndresMWeber / update_local_lowercase_variables.py
Last active March 8, 2017 22:52
Takes locally definted variables from a script and takes any lowercase variables and creates an uppercase version, case study."
PRE = set(locals())
a = 5
B = 4
def UPPER_CONVERT(vars):
for var in vars:
if not var.isupper():
varname = var
# Obtain global variable value
exec('global %s' % var)
@AndresMWeber
AndresMWeber / mayapy.py
Last active December 13, 2018 07:21
Execute Python as Mayapy
import os
import sys
#https://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/Maya/files/GUID-C0F27A50-3DD6-454C-A4D1-9E3C44B3C990-htm.html
#======================================================#
#THESE ARE THE MISSING STUFF FOR SIMULATING mayapy.exe ENV
#======================================================#
os.environ["MAYA_LOCATION"] = "C:\\Program Files\\Autodesk\\Maya2017"
os.environ["PYTHONHOME"] = "C:\\Program Files\\Autodesk\\Maya2017\\Python"
os.environ["PATH"] = "C:\\Program Files\\Autodesk\\Maya2017\\bin;" + os.environ["PATH"]
@AndresMWeber
AndresMWeber / CompareJointHierarchies.py
Last active February 9, 2017 20:36
Compares two joints hierarchies in Maya and returns the differences between the two hierarchies as a keyed dictionary
import pymel.core as pm
import re
from pprint import pprint
def compare_joint_hierarchies():
report = {}
top_group_a, top_group_b = pm.ls(sl=True)[:2]
report['top_group_a'] = str(top_group_a.name())
report['top_group_b'] = str(top_group_b.name())
def gen_dict_key_matches(key, dictionary, path=None, full_path=False):
if path is None:
path = []
for k, v in iteritems(dictionary):
path.append(k)
if k == key:
yield (path, v) if full_path else v
elif isinstance(v, dict):
for result in gen_dict_key_matches(key, v, path):
@AndresMWeber
AndresMWeber / set_all_aovIds.py
Last active January 20, 2017 21:30 — forked from anonymous/set_shader_attribute.py
Set all shader attributes to a new prefixed and indexed string
import pymel.core as pm
def set_all_aovIds(value, targets=None, object_type='alSurface', padding=2, attr_basename='aovId', number_of_indexes=8, use_selection=True):
if not targets:
targets = pm.ls(type=object_type, sl=use_selection)
for target in targets:
for index in range(1, number_of_indexes+1):
try:
new_value = '%s_%{PAD}d'.format(PAD='0' + str(padding)) % (value, index)
@AndresMWeber
AndresMWeber / sdk_connect
Created July 5, 2016 21:45
Boiler plate function for SDK creation
def connect_sdk(driverAttr, drivenObj, attribute, driverValues=[], drivenValues=[]):
for driverValue, drivenValue in zip(driverValues, drivenValues):
pm.setDrivenKeyframe(drivenObj,
currentDriver=driverAttr,
at=attribute,
driverValue=driverValue,
value=drivenValue)
@AndresMWeber
AndresMWeber / automation.md
Created June 17, 2016 19:55 — forked from cube-drone/automation.md
Automation For The People

Automation for the People

Long ago, the first time I read "The Pragmatic Programmer", I read some advice that really stuck with me.

"Don't Use Manual Procedures".

This in the chapter on Ubiquitous Automation. To summarize, they want you to automate all the things.

The trouble was that I hadn't much of an idea how to actually go