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 / file_import.py
Created April 3, 2017 01:47
Return imported top nodes from maya.cmds import
import maya.cmds as mc
file = "D:/dev/procedural_rigging/assets/komodo/model/komodo_model.mb"
new_nodes = mc.file(file, i=True, returnNewNodes=True)
print cmds.ls(new_nodes, assemblies=True)[0]
class MayaElement(AbstractElement):
def __init__(self,
group_top='',
group_model='',
group_joint='',
group_nodes='',
group_world='',
parent='',
scale=1.0,
**kwargs):
@AndresMWeber
AndresMWeber / delegate.py
Last active April 6, 2017 22:29
Trying to delegate but inherit.
# Delegator
class Delegate(object):
def __init__(self):
pass
def name(self):
print 'yo'
class HasDelegate(object):
def __init__(self):
import sys
from PySide2.QtWidgets import *
import maya.standalone as ms
import maya.cmds as mc
class Window(QWidget):
def __init__(self):
super(Window, self).__init__()
self.setupUI()
@AndresMWeber
AndresMWeber / cache.py
Created May 4, 2017 03:56
Property caching decorator/property subclass
"""
Stolen from:
https://bytes.com/topic/python/answers/751180-how-memoize-cache-property-access
"""
class cached(property):
'Convert a method into a cached attribute'
def __init__(self, method):
private = '_' + method.__name__
def fget(s):
try:
@AndresMWeber
AndresMWeber / faux_wireframe.py
Created June 2, 2017 00:08
Create curve dense fake wireframe of component edges converted to degree 1 curves
import maya.cmds as cmds
cmds.refresh(suspend=True)
selection_edges = cmds.filterExpand(cmds.polyListComponentConversion(te=1), sm=32, ex=1)
curve_transforms = []
for edge in selection_edges:
vertices = cmds.ls(cmds.polyListComponentConversion(edge, fe=1, tv=1), fl=1)
created_curve = cmds.curve(d=1, p=[cmds.pointPosition(vertex) for vertex in vertices])
@AndresMWeber
AndresMWeber / service.py
Last active August 14, 2017 20:50
Trying to figure out implementing services pattern
import maya.cmds as cmds
platform = cmds
class EventService(object):
def __init__(self):
self.events = []
self.event_log = []
def add_event(self, event):
@AndresMWeber
AndresMWeber / node_types.py
Last active October 5, 2017 20:50
node registration
import sys
from joint import Joint
from transform import Transform
from unicode_delegate import UnicodeDelegate
from dag_node import DagNode
from curve import Curve
REGISTERED_NODES = {}
import maya.cmds as mc
"""
I have two lists:
1. Materials
2. Locators
I want to compare each list and if the locator has the same name as the material then:
getAttr transforms from the locator and setAttr color to the material.
If I define the name of the material and locator as 'someMaterial', it works.
@AndresMWeber
AndresMWeber / validator.py
Last active November 21, 2017 20:37
Input Validator Abstraction
from functools import wraps
def verify_inputs(filterers=None, validators=None):
""" Verify the inputs going into any function with equal length lists of:
filterers (for filtering out objects we do not care about) and
validators (to check the object itself is valid).
"""
filterers = filterers if filterers is not None else []
validators = validators if validators is not None else []