def mirror_controlShape(source=None, target=None, colorDirection='right', controlType='main'): _str_func = "mirror_controlShape" if target is None: _sel = mc.ls(sl=True) if len(_sel) == 2: return mirror_controlShape(_sel[0], _sel[1]) if not source: raise ValueError, "|{0}| >> Must have a source".format(_str_func) if not target: raise ValueError, "|{0}| >> Must have a target".format(_str_func) _dup_curve = mc.duplicate(source)[0] for child in TRANS.children_get(_dup_curve, True): mc.delete(child) ATTR.set_standardFlags(_dup_curve, lock=False, keyable=True, visible=True) _grp = mc.group(em=True) _dup_curve = TRANS.parent_set(_dup_curve, _grp) ATTR.set(_grp, 'scaleX', -1) _dup_curve = TRANS.parent_set(_dup_curve, False) mc.makeIdentity(_dup_curve, apply=True, translate=True, rotate=True, scale=False) return shapeParent_in_place(target, _dup_curve, True, True) mc.delete(_grp) colorControl(target, colorDirection, controlType) mc.select(target) return target
def create_at(obj=None, create='null', midPoint=False, l_pos=[], baseName='created'): """ Create a null matching a given obj :parameters: obj(str): Object to modify create(str): What to create :returns name(str) """ _str_func = 'create_at' obj = VALID.mNodeString(obj) _create = create log.debug("|{0}| >> obj:{1}".format(_str_func, obj)) log.debug("|{0}| >> create:{1}".format(_str_func, _create)) if midPoint: _d = TRANS.POS.get_midPointDict(obj) objTrans = _d['position'] objRot = _d['rotation'] objRotAxis = None elif _create in ['null', 'joint']: objTrans = TRANS.position_get( obj) #mc.xform (obj, q=True, ws=True, rp=True) objRot = TRANS.orient_get( obj) #mc.xform (obj, q=True, ws=True, ro=True) objRotAxis = mc.xform(obj, q=True, ws=True, ra=True) if _create == 'null': _created = mc.group(w=True, empty=True) if not midPoint: mc.xform(_created, roo=mc.xform(obj, q=True, roo=True)) #...match rotateOrder mc.move(objTrans[0], objTrans[1], objTrans[2], [_created]) mc.xform(_created, ws=True, ro=objRot, p=False) if objRotAxis: mc.xform(_created, ws=True, ra=objRotAxis, p=False) elif _create == 'joint': mc.select(cl=True) _created = mc.joint() if not midPoint: mc.xform(_created, roo=mc.xform(obj, q=True, roo=True)) #...match rotateOrder mc.move(objTrans[0], objTrans[1], objTrans[2], [_created]) mc.xform(_created, ws=True, ro=objRot, p=False) if objRotAxis: mc.xform(_created, ws=True, ra=objRotAxis, p=False) elif _create in ['curve', 'curveLinear', 'linearTrack', 'cubicTrack']: if not l_pos: l_pos = [] #_sel = mc.ls(sl=True,flatten=True) for i, o in enumerate(obj): p = TRANS.position_get(o) log.debug("|{0}| >> {3}: {1} | pos: {2}".format( _str_func, o, p, i)) l_pos.append(p) if len(l_pos) <= 1: raise ValueError, "Must have more than one position to create curve" if _create in ['linearTrack', 'cubicTrack']: _d = 1 if _create == 'cubicTrack': _d = 3 _trackCurve = mc.curve(d=1, p=l_pos) _trackCurve = mc.rename(_trackCurve, "{0}_trackCurve".format(baseName)) l_clusters = [] #_l_clusterParents = [mStartHandle,mEndHandle] for i, cv in enumerate( mc.ls(['{0}.cv[*]'.format(_trackCurve)], flatten=True)): _res = mc.cluster(cv, n='{0}_{1}_cluster'.format(baseName, i)) TRANS.parent_set(_res[1], obj[i]) ATTR.set(_res[1], 'visibility', 0) l_clusters.append(_res) ATTR.set(_res[1], 'visibility', False) return _trackCurve, l_clusters elif _create == 'curve': knot_len = len(l_pos) + 3 - 1 _created = mc.curve(d=3, ep=l_pos, k=[i for i in range(0, knot_len)], os=True) else: _created = mc.curve(d=1, ep=l_pos, k=[i for i in range(0, len(l_pos))], os=True) log.debug("|{0}| >> created: {1}".format(_str_func, _created)) elif _create == 'locator': raise NotImplementedError, "locators not done yet" else: raise NotImplementedError, "|{0}| >> unknown mode: {1}".format( _str_func, _create) mc.select(_created) return _created
def create_proxyGeo(proxyShape='cube', size=[1, 1, 1], direction='z+', ch=True): try: #cube:sphere:cylinder:cone:torus _str_func = 'create_proxyGeo' _proxyShape = _d_proxyCreate.get(proxyShape, proxyShape) _call = getattr(mc, _proxyShape, None) if not _call: raise ValueError, "Failed to find maya.cmds call {0}".format( _proxyShape) #if proxyShape not in _d_create.keys(): #raise ValueError,"Unknown shape: {0}".format(proxyShape) _kws = {'ch': ch} if proxyShape in ['cube']: _kws['width'] = size[0] _kws['ch'] = False if proxyShape in ['cylinder', 'sphere', 'cone', 'cylinder', 'torus']: _kws['radius'] = max(size) / 2.0 _kws['axis'] = VALID.simpleAxis(direction).p_vector _res = _call(**_kws) if size is not None: if VALID.isListArg(size): TRANS.scale_to_boundingBox(_res[0], size) else: if absoluteSize: _f_current = DIST.get_bb_size(_res[0], True, True) multiplier = size / _f_current mc.scale(multiplier, multiplier, multiplier, _res[0], relative=True) else: mc.scale(size, size, size, _res[0], os=True) #mc.makeIdentity(_res[0], apply=True,s=1) """ if proxyShape == 'cube': _d_directionXRotates = {'x+':[0,0,0],'x-':[0,180,0],'y+':[0,0,90],'y-':[0,0,-90],'z+':[0,-90,0],'z-':[0,90,0]} _r_factor = _d_directionXRotates.get(direction) mc.rotate (_r_factor[0], _r_factor[1], _r_factor[2], _res[0], ws=True)""" #mc.makeIdentity(_res[0], apply=True,r =1, n= 1) if proxyShape == 'cube': _children = TRANS.children_get(_res[0]) for i, c in enumerate(_children): _children[i] = TRANS.parent_set(c, False) combineShapes(_children + [_res[0]], keepSource=False, replaceShapes=False) return _res except Exception, err: cgmGEN.cgmExceptCB(Exception, err, msg=vars())
def create_localAxisProxyBAK(obj=None): """ Make a local axis box around a given object so that you can then """ try: _str_func = 'create_localAxisProxy' _dag = VALID.getTransform(obj) if not _dag: raise ValueError, "Must have a dag node" l_shapes = TRANS.shapes_get(_dag) _dup = mc.duplicate(l_shapes, po=False, rc=True)[0] #_dup = TRANS.parent_set(_dup,False) #Get some values... t = ATTR.get(_dup, 'translate') r = ATTR.get(_dup, 'rotate') s = ATTR.get(_dup, 'scale') o = TRANS.orient_get(_dup) shear = ATTR.get(_dup, 'shear') _scaleLossy = TRANS.scaleLossy_get(_dag) #Reset our stuff before we make our bb... TRANS.orient_set(_dup, (0, 0, 0)) ATTR.set(_dup, 'scale', [1, 1, 1]) _size = POS.get_bb_size(_dup, True) import cgm.core.lib.math_utils as COREMATH reload(COREMATH) #_proxy = create_proxyGeo('cube',COREMATH.list_div(_scaleLossy,_size)) _proxy = create_proxyGeo('cube', _size) mc.makeIdentity(_proxy, apply=True, scale=True) return #mc.xform(_proxy, scale = _size, worldSpace = True, absolute = True) #Parent it to the dup... _proxy = TRANS.parent_set(_proxy, _dup) ATTR.reset(_proxy, ['t', 'r', 'shear']) #_dup = TRANS.parent_set(_dup, TRANS.parents_get(_dag)) SNAP.go(_dup, _dag) ATTR.set(_dup, 'shear', shear) #TRANS.scaleLocal_set(_dup, s) #mc.delete(_dup) #_scaleLossy = TRANS.scaleLossy_get(_dag) #import cgm.core.lib.math_utils as COREMATH #TRANS.scaleLocal_set(_dup, COREMATH.list_mult([-1.0,-1.0,-1.0],_scaleLossy,)) #proxy = TRANS.parent_set(_proxy, False) cgmGEN.func_snapShot(vars()) #ATTR.set(_dup,'translate',t) #ATTR.set(_dup,'rotate',r) #SNAP.go(_proxy[0],_dag) #ATTR.set(_proxy[0],'scale',_scaleLossy) #TRANS.scaleLocal_set(_dup,[1,1,1]) #ATTR.set(_dup,'shear',[0,0,0]) #_proxy = TRANS.parent_set(_proxy, False) #TRANS.scaleLocal_set(_proxy,_scaleLossy) #ATTR.set(_dup,'scale',s) return mc.rename(_proxy, "{0}_localAxisProxy".format(NAMES.get_base(_dag))) except Exception, err: 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())
_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) TRANS.is_parentTo(_root,TRANS.parents_get(_root)[0])