Created
October 6, 2013 13:03
-
-
Save robomojo/6853806 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymel.core as pm | |
import re | |
from pprint import pprint | |
class NodeGetter: | |
def __init__(self,args): | |
''' | |
Unpacks args to: nodename, searchmethod. | |
''' | |
( | |
self.nodename, | |
self.searchmethod, | |
) = args | |
def getListOfNodes (self,nodes): | |
''' | |
Expects a list of maya nodes, returns matches. | |
''' | |
l = [] | |
use_regex = self.searchmethod == 'strict' | |
search = self.nodename | |
for each in nodes: | |
shortname = each.name().replace(':','|').split('|')[-1] | |
if use_regex: correctname = re.search(search,shortname) is not None | |
else: correctname = shortname == search | |
if correctname: | |
l.append(each) | |
return l | |
def isName (self,nodes): | |
''' | |
Confirms the passed node. | |
''' | |
class ConstraintChecker(NodeGetter): | |
''' | |
Extends NodeGetter to include constraint options. | |
''' | |
def __init__(self,args): | |
''' | |
Unpacks args to: nodename, searchmethod. Adds group, part, constraints. | |
''' | |
( | |
self.nodename, | |
self.searchmethod, | |
self.group, | |
self.part, | |
self.constraints, | |
) = args | |
# fix annoying tuples | |
self.constraints = (self.constraints,) if type(self.constraints) is not tuple else self.constraints | |
trs = 'translate','rotate','scale' | |
t,r,s = trs | |
strict,loose = 'strict','loose' | |
values = ( | |
( | |
'carBoneName', | |
strict, | |
'car', | |
'body', | |
(t,s), | |
), | |
( | |
'carBoneName2', | |
strict, | |
'car', | |
'body', | |
(t,s), | |
), | |
( | |
'cameraBoneName', | |
strict, | |
'cam', | |
'camera', | |
t, | |
), | |
( | |
'slidernode', | |
strict, | |
'ui', | |
'slider', | |
s, | |
), | |
) | |
for each in values: | |
val = ConstraintChecker(each) | |
pprint (vars(val)) | |
# for each in values: | |
# group,name,constraints,searchmethod = each | |
# fix annoying tuples | |
# constraints = (constraints,) if type(constraints) is not tuple else constraints | |
# inName | |
# isName | |
# name().replace(':','|').split('|')[-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment