def get_midPointDict(sourceList, forceBBCenter=False): _l_info = [] _l_pos = [] _l_rot = [] for s in sourceList: _d = POS.get_info(s, boundingBox=forceBBCenter) _l_pos.append(_d['position']) _l_rot.append(_d['rotation']) _l_info.append(_d) _d = _l_info[0] _d['position'] = MATH.get_average_pos(_l_pos) _d['rotation'] = MATH.get_average_pos(_l_rot) #position(_target,_d) return _d
def get_midPointDict(sourceList, forceBBCenter=False): _str_func = 'get_midPointDict' _d_info = {} _l_pos = [] _l_rot = [] for s in sourceList: log.debug("|{0}| >> Checking source: {1}'".format(_str_func, s)) _d_shape = get_info(s, boundingBox=forceBBCenter) _l_pos.append(_d_shape['position']) _l_rot.append(_d_shape['rotation']) _d_info[s] = _d_shape #_d_info['info'] = _d_info _d_info['positions'] = _l_pos _d_info['rotations'] = _l_rot _d_info['position'] = MATH.get_average_pos(_l_pos) _d_info['rotation'] = MATH.get_average_pos(_l_rot) return _d_info
def get(obj=None, pivot='rp', space='ws', targets=None, mode='xform', asEuclid=False): """ General call for querying position data in maya. Note -- pivot and space are ingored in boundingBox mode which returns the center pivot in worldSpace :parameters: obj(str): Object to check Transform, components supported pivot(str): Which pivot to use. (rotate,scale,boundingBox) rotatePivot scalePivot boundingBox -- Returns the calculated center pivot position based on bounding box space(str): World,Object,Local mode(str): xform -- Utilizes tranditional checking with xForm or pointPosition for components asEuclid(bool) - whether to return as Vector or not :returns success(bool) """ try: _str_func = 'get_pos' _obj = VALID.mNodeString(obj) _pivot = VALID.kw_fromDict(pivot, SHARED._d_pivotArgs, noneValid=False, calledFrom=_str_func) _targets = VALID.stringListArg(targets, noneValid=True, calledFrom=_str_func) _space = VALID.kw_fromDict(space, SHARED._d_spaceArgs, noneValid=False, calledFrom=_str_func) _mode = VALID.kw_fromDict(mode, _d_pos_modes, noneValid=False, calledFrom=_str_func) _res = False if _pivot == 'boundingBox': log.debug("|{0}|...boundingBox pivot...".format(_str_func)) _res = get_bb_center(_obj) if MATH.is_vector_equivalent( _res, [0, 0, 0]) and not mc.listRelatives(_obj, s=True): _pivot = 'rp' log.warning( "|{0}|...boundingBox pivot is zero, using rp....".format( _str_func)) if '[' in _obj: log.debug("|{0}| >> component mode...".format(_str_func)) if ":" in _obj.split('[')[-1]: raise ValueError, "|{0}| >>Please specify one obj. Component list found: {1}".format( _str_func, _obj) #_cType = VALID.get_mayaType(_obj) _l_comp = VALID.get_component(_obj) _root = _l_comp[1] _cType = _l_comp[3] if not VALID.is_shape(_root): _shapes = mc.listRelatives(_root, s=True, fullPath=True) or [] if len(_shapes) > 1: log.warning( "|{0}| >>More than one shape found. To be more accurate, specify: {1} | shapes: {2}" .format(_str_func, _obj, _shapes)) _root = _shapes[0] _OBJ = '.'.join([_root, _l_comp[0]]) log.debug( "|{0}| >> obj: {1}({6}) | type: {2} | pivot: {3} | space: {4} | mode: {5}" .format(_str_func, _OBJ, _cType, _pivot, _space, _mode, _obj)) kws_pp = {'world': False, 'local': False} if _space == 'world': kws_pp['world'] = True else: kws_pp['local'] = True if _cType == 'polyVertex': _res = mc.pointPosition(_OBJ, **kws_pp) elif _cType == 'polyEdge': mc.select(cl=True) mc.select(_OBJ) mel.eval("PolySelectConvert 3") edgeVerts = mc.ls(sl=True, fl=True) posList = [] for vert in edgeVerts: posList.append(mc.pointPosition(vert, **kws_pp)) _res = MATH.get_average_pos(posList) elif _cType == 'polyFace': mc.select(cl=True) mc.select(_OBJ) mel.eval("PolySelectConvert 3") edgeVerts = mc.ls(sl=True, fl=True) posList = [] for vert in edgeVerts: posList.append(mc.pointPosition(vert, **kws_pp)) _res = MATH.get_average_pos(posList) elif _cType in [ 'surfaceCV', 'curveCV', 'editPoint', 'surfacePoint', 'curvePoint', 'cv', 'bezierCurve' ]: _res = mc.pointPosition(_OBJ, **kws_pp) #_res = mc.pointPosition(_OBJ) else: raise RuntimeError, "|{0}| >> Shouldn't have gotten here. Need another check for component type. '{1}'".format( _str_func, _cType) else: log.debug( "|{0}| >> obj: {1} | pivot: {2} | space: {3} | mode: {4} | asEuclid: {5}" .format(_str_func, _obj, _pivot, _space, _mode, asEuclid)) if _space == 'local' or _pivot == 'local': _res = ATTR.get(_obj, 'translate') #elif _pivot == 'local': #if _space == 'world': # _res = mc.xform(_obj, q=True, rp = True, ws=True ) #else: # _res = ATTR.get(_obj,'translate') else: kws = { 'q': True, 'rp': False, 'sp': False, 'os': False, 'ws': False } if _pivot == 'rp': kws['rp'] = True else: kws['sp'] = True if _space == 'object': kws['os'] = True else: kws['ws'] = True log.debug("|{0}| >> xform kws: {1}".format(_str_func, kws)) _res = mc.xform(_obj, **kws) if _res is not None: if asEuclid: log.debug("|{0}| >> asEuclid...".format(_str_func)) return EUCLID.Vector3(_res[0], _res[1], _res[2]) return _res raise RuntimeError, "|{0}| >> Shouldn't have gotten here: obj: {1}".format( _str_func, _obj) except Exception, err: cgmGen.cgmExceptCB(Exception, err)