def dag_sort(objList=None): """ Dag sort children under their parent """ _str_func = 'dag_sort' if not objList: objList = mc.ls(sl=1) else: objList = VALID.mNodeStringList(objList) log.info("|{0}| >> ObjList: {1} ".format(_str_func, objList)) d_p = {} l_p = [] l_world = [] for o in objList: p = TRANS.parent_get(o) if not p: l_world.append(o) elif p not in l_p: l = TRANS.children_get(p) or [] l.sort() l.reverse() for c in l: try: mc.reorder(c, front=True) except Exception, err: print err
def get_objNameDict(obj, ignore=[False]): """ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION: Returns a generated dictionary of name info ARGUMENTS: obj(string) - object ignore(string) - default is 'none', only culls out cgmtags that are generated via returnCGMOrder() function RETURNS: namesDict(string) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> """ try: _str_funcName = "get_objNameDict" log.debug(">>> %s >>> " % (_str_funcName) + "=" * 75) if type(ignore) is not list: ignore = [ignore] namesDict = {} divider = returnCGMDivider() order = returnCGMOrder() nameBuilder = [] #>>> Get our cgmVar_iables #userAttrs = attributes.returnUserAttributes(obj) #cgmAttrs = lists.returnMatchList(userAttrs,order) #>>> Tag ignoring if ignore: for i in ignore: if i in order: order.remove(i) #>>> Geting our data for tag in order: tagInfo = SEARCH.get_tagInfo(obj, tag) if tagInfo is not False: namesDict[tag] = (tagInfo) if 'cgmIterator' in order: _iterator = ATTR.get(obj, 'cgmIterator') if _iterator is not False: log.debug("Iterator found") namesDict['cgmIterator'] = (_iterator) # remove tags up stream that we don't want if they don't exist on the actual object""" if not mc.objExists(obj + '.cgmTypeModifier'): if namesDict.get('cgmTypeModifier') != None: namesDict.pop('cgmTypeModifier') log.debug("%s >>> initial nameDict: %s " % (_str_funcName, namesDict)) #>>> checks if the names exist as objects or it's a shape node ChildNameObj = False nameObj = False cgmNameAttrType = ATTR.get_type(obj, 'cgmName') log.debug("cgmNameAttrType: {0}".format(cgmNameAttrType)) if cgmNameAttrType == 'message': #nameObj = SEARCH.get_nodeTagInfo(obj,'cgmName') nameObj = ATTR.get_message( obj, 'cgmName', simple=True) #SEARCH.get_nodeTagInfo(obj,'cgmName') if nameObj: nameObj = nameObj[0] nameObjDict = get_objNameDict(nameObj) #pprint.pprint(nameObjDict) for k in 'cgmDirection', 'cgmPosition': #if nameObjDict.get(k) and namesDict.get(k): try: namesDict.pop(k) except: pass log.debug("nameObj: {0}".format(nameObj)) namesDict['cgmName'] = names.getBaseName(nameObj) return namesDict typeTag = SEARCH.get_nodeTagInfo(obj, 'cgmType') isType = SEARCH.VALID.get_mayaType(obj) isShape = SEARCH.VALID.is_shape(obj) """first see if it's a group """ if isType == 'group' and typeTag == False: childrenObjects = TRANS.children_get(obj, False) log.debug("%s >>> group and no typeTag..." % (_str_funcName)) """ if it's a transform group """ groupNamesDict = {} if not nameObj: groupNamesDict['cgmName'] = childrenObjects[0] else: groupNamesDict['cgmName'] = nameObj groupNamesDict['cgmType'] = CORESHARE.d_cgmTypes.get('transform') if namesDict.get('cgmTypeModifier') != None: groupNamesDict['cgmTypeModifier'] = namesDict.get( 'cgmTypeModifier') return groupNamesDict """ see if there's a name tag""" elif isType in ['joint']: return namesDict elif isShape: #If we have a name object or shape log.debug("%s >>> nameObj not None or isType is 'shape'..." % (_str_funcName)) if isShape: #log.debug("%s >>> nameObj exists: '%s'..."%(_str_funcName,nameObj)) #Basic child object with cgmName tag childNamesDict = {} childNamesDict['cgmName'] = namesDict.get('cgmName') childNamesDict['cgmType'] = namesDict.get('cgmType') if namesDict.get('cgmTypeModifier') != None: childNamesDict['cgmTypeModifier'] = namesDict.get( 'cgmTypeModifier') if namesDict.get('cgmIterator') != None: childNamesDict['cgmIterator'] = namesDict.get( 'cgmIterator') return childNamesDict elif isShape or 'Constraint' in isType: """if so, it's a child name object""" log.debug("%s >>> child name object..." % (_str_funcName)) childNamesDict = {} childNamesDict['cgmName'] = TRANS.parent_get(obj, False) childNamesDict['cgmType'] = namesDict.get('cgmType') return childNamesDict else: log.debug("%s >>> No special case found. %s" % (_str_funcName, namesDict)) return namesDict else: return namesDict except Exception, err: raise cgmGEN.cgmExceptCB(Exception, err, msg=vars())
def create_axisProxy(obj=None): """ Make a local axis box around a given object so that you can then """ try: _str_func = 'create_axisProxy' _dag = VALID.getTransform(obj) if not _dag: raise ValueError, "Must have a dag node. Obj: {0}".format(obj) if VALID.is_shape(obj): l_shapes = [obj] else: l_shapes = TRANS.shapes_get(_dag, True) _parent = TRANS.parent_get(_dag) _dup = mc.duplicate(l_shapes, po=False, rc=True)[0] #TRANS.pivots_recenter(_dup) _dup = TRANS.parent_set(_dup, False) ATTR.set_standardFlags(_dup, lock=False, keyable=True) #Get some values... l_reset = ['t', 'r', 's', 'shear', 'rotateAxis'] t = ATTR.get(_dup, 'translate') r = ATTR.get(_dup, 'rotate') s = ATTR.get(_dup, 'scale') ra = ATTR.get(_dup, 'rotateAxis') if ATTR.has_attr(_dup, 'jointOrient'): l_reset.append('jointOrient') jo = ATTR.get(_dup, 'jointOrient') o = TRANS.orient_get(_dup) shear = ATTR.get(_dup, 'shear') _scaleLossy = TRANS.scaleLossy_get(_dag) #Reset our stuff before we make our bb... ATTR.reset(_dup, l_reset) _size = POS.get_bb_size(_dup, True) #_proxy = create_proxyGeo('cube',COREMATH.list_div(_scaleLossy,_size)) _proxy = create_proxyGeo('cube', _size) mc.makeIdentity(_proxy, apply=True, scale=True) #Now Put it back _dup = TRANS.parent_set(_dup, TRANS.parent_get(_dag)) _proxy = TRANS.parent_set(_proxy, _dup) #_dup = TRANS.parent_set(_dup, TRANS.parents_get(_dag)) SNAP.go(_dup, _dag) #ATTR.set(_dup,'s',(0,0,0)) ATTR.reset(_dup, ['s', 'shear']) ATTR.reset(_proxy, ['t', 'r', 's', 'shear', 'rotateAxis']) _proxy = TRANS.parent_set(_proxy, _dag) ATTR.reset(_proxy, ['t', 'r', 's', 'shear', 'rotateAxis']) #match_transform(_proxy,_dag) #SNAP.go(_proxy,_dag,pivot='bb') #cgmGEN.func_snapShot(vars()) _proxy = TRANS.parent_set(_proxy, False) mc.delete(_dup) #match_transform(_proxy,_dag) return mc.rename(_proxy, "{0}_localAxisProxy".format(NAMES.get_base(_dag))) except Exception, err: cgmGEN.cgmExceptCB(Exception, err, msg=vars())
_scale = [1,2,1] _rot = TRANS.rotate_get('NotBatman_master_block1',True) TRANS.translate_set(_root,_pos) TRANS.position_set(_root,_pos) TRANS.rotate_set(_root,_rot) TRANS.eulerAngles_set(_root,_rot) TRANS.orient_set(_root,_rot) TRANS.orientObject_set(_root,_rot) TRANS.rotateAxis_set(_root,_rot) TRANS.scaleLocal_set(_root,_scale) #...heirarchy _rootRoot = 'group2' TRANS.parent_get(_root) TRANS.parent_set(_root,TRANS.parent_get(_root)) TRANS.parents_get(_root) TRANS.children_get(_rootRoot) TRANS.descendents_get(_rootRoot) TRANS.is_childTo(_root,TRANS.parents_get(_root)[0]) TRANS.is_childTo(_root,None) TRANS.is_parentTo(_rootRoot, _root) TRANS.is_parentTo(_root, _rootRoot) cgmMeta.cgmObject(_rootRoot).getListPathTo(_root) TRANS.get_listPathTo(_rootRoot, _root,False) cgmMeta.cgmObject(_root).getListPathTo(_rootRoot) TRANS.get_listPathTo(_root, _rootRoot,False)