Exemplo n.º 1
0
def create_controlResizeObj(target=None):
    _str_func = "create_controlResizeObj"
    if target is None:
        _sel = mc.ls(sl=True)
        if _sel:
            _res = []
            for t in _sel:
                _res.append(create_controlResizeObj(t))
            return _res

    if not target:
        raise ValueError, "|{0}|  >> Must have a target".format(_str_func)

    if ATTR.get_message(target, 'cgmControlResizer'):
        return ATTR.get_message(target, 'cgmControlResizer')

    handle = create_at(target, 'null')
    ATTR.set_message(target, 'cgmControlResizer', handle)
    ATTR.set_message(handle, 'cgmControlResizerSource', target)

    handle = mc.rename(handle, NAMES.base(target) + '_cgmResizer')

    shapeParent_in_place(handle, target)

    ATTR.set(target, 'template', 1)

    return handle
Exemplo n.º 2
0
def create_distanceMeasure(start=None, end=None, baseName='measure'):
    """
    Get the the closest return based on a source and target and variable modes
    
    :parameters:
        :start(str): Our start obj
        :end(str): End obj
        :baseName(str):What mode are we checking data from
    
    :returns
        {shape,dag,loc_start,loc_end,start,end}
    """
    try:
        _str_func = 'create_distanceMeasure'

        #Create ====================================================================================
        plug_start = POS.get_positionPlug(start)
        plug_end = POS.get_positionPlug(end)
        _res = {'start': start, 'end': end}

        if not plug_start:
            pos_start = POS.get(start)
            loc_start = mc.spaceLocator(name="{0}_{1}_start_loc".format(
                NAMES.get_base(start), baseName))[0]
            POS.set(loc_start, pos_start)
            plug_start = POS.get_positionPlug(loc_start)
            _res['loc_start'] = loc_start
        if not plug_end:
            pos_end = POS.get(end)
            loc_end = mc.spaceLocator(name="{0}_{1}_end_loc".format(
                NAMES.get_base(end), baseName))[0]
            POS.set(loc_end, pos_end)
            plug_end = POS.get_positionPlug(loc_end)
            _res['loc_end'] = loc_end

        mDistShape = r9Meta.MetaClass(mc.createNode('distanceDimShape'))
        mDistShape.rename("{0}_distShape".format(baseName))

        mDistTrans = r9Meta.MetaClass(VALID.getTransform(mDistShape.mNode))
        mDistTrans.rename("{0}_dist".format(baseName))

        _res['dag'] = mDistTrans.mNode
        _res['shape'] = mDistShape.mNode

        ATTR.set_message(_res['dag'], 'distShape', _res['shape'], simple=True)

        ATTR.connect(plug_start, "{0}.startPoint".format(_res['shape']))
        ATTR.connect(plug_end, "{0}.endPoint".format(_res['shape']))

        return _res
    except Exception, err:
        cgmGen.cgmExceptCB(Exception, err)
Exemplo n.º 3
0
def matchTarget_set(obj = None, target = None):
    """
    Set the match target of an object
    
    :parameters:
        obj(str): Object to modify
        target(str): Target to match

    :returns
        success(bool)
    """     
    _str_func = 'matchTarget_set'
        
    _obj = VALID.objString(obj, noneValid=False, calledFrom = __name__ + _str_func + ">> validate obj")
    _target = VALID.objString(target, noneValid=False, calledFrom = __name__ + _str_func + ">> validate target")
    
    ATTR.set_message(_obj, 'cgmMatchTarget',_target,'cgmMatchDat',0)
    
    return True
Exemplo n.º 4
0
def create(target=None,
           position=None,
           tag=True,
           setMatchTarget=True,
           pivot='rp',
           mode='fromTarget',
           name=None):
    """
    Return the short name of an object

    :parameters
        :target(str): What to create a loc from
        :tag(bool): Whether to tag for updating or special naming
        :pivot: Whether to force it to be created at the rotatePivot, scalePivot or BoundingBox center
        :mode
            fromTarget -- can be component or transform
            midPoint -- mid point of specfied targets
            closestPointOnTarget -- closest point from source to targets
            closestTarget -- closest target from source
            rayCast -- create a rayCast locator. For more options, see LOCINATOR
            attachPoint -- Create a rayCast follicle, and parent your loc to that.
        :setMatchTarget
    :returns
        short name(str)
    """
    _str_func = "create"

    try:
        if mode == 'rayCast':
            #_catch = mc.group(em=True)
            class rayCastLoc(cgmDrag.clickMesh):
                def release_post_insert(self):
                    #ATTR.set_messagse(_catch, 'tmpMsg', self.l_created[-1])
                    _loc = self.l_created[-1]
                    _mLoc = r9Meta.MetaClass(_loc)
                    _buffer = _mLoc.cgmLocDat
                    _target = ATTR.get_message(_loc, 'meshTarget')[0]
                    _loc = mc.rename(
                        _loc, "{0}_u{1}_v{2}_rayCast_loc".format(
                            coreNames.get_base(_target),
                            "{0:.4f}".format(_buffer['uv'][0]),
                            "{0:.4f}".format(_buffer['uv'][1]),
                        ))
                    self.dropTool()

            rayCastLoc(create='locator')
            #_res = ATTR.get_message(_catch,'tmpMsg')[0]
            return True

        _loc = mc.spaceLocator()[0]

        if position:
            mc.move(position[0], position[1], position[2], _loc, ws=True)
            if name:
                return mc.rename(_loc, name)
            return mc.rename("pos_loc")
        if not target:
            if name:
                return mc.rename(_loc, name)
            return mc.rename(_loc, "world_center_loc")

        _targets = VALID.objStringList(target,
                                       noneValid=False,
                                       calledFrom=__name__ + _str_func +
                                       ">> validate target")
        #_targets = VALID.listArg(target)
        if tag or mode:
            _mi_loc = r9Meta.MetaClass(_loc)
            if not _mi_loc.hasAttr('cgmLocDat'):
                _mi_loc.addAttr('cgmLocDat', attrType='string')

        log.debug("|{0}| >> {1} mode...".format(_str_func, mode))

        if mode in ['fromTarget', 'attachPoint']:
            if len(_targets) != 1:
                log.warning("|{0}| >> mode: {1} | targets: {2} | ".format(
                    _str_func, mode, _targets))
                raise ValueError, "May only have one target for mode: {0} | targets: {1}".format(
                    mode, _targets)

            _target = _targets[0]

            if name:
                _loc = mc.rename(_loc, name)
            else:
                _loc = mc.rename(
                    _loc,
                    "{0}_fromTarget_loc".format(coreNames.get_base(_target)))

            if tag:  #store info
                ATTR.store_info(_loc,
                                'cgmName',
                                coreNames.get_base(_target),
                                attrType='string',
                                lock=True)
                ATTR.store_info(_loc, 'cgmLocMode', 'fromTarget', lock=True)
                ATTR.set_message(_loc, 'cgmLocSource', _target, 'cgmLocDat')
                if not VALID.is_component(_target) and setMatchTarget:
                    SNAP.matchTarget_set(_target, _loc)
                #_d = r9Meta.MetaClass(_loc).cgmLocDat

                _res = update(_loc)
            _res = update(_loc, _target, 'fromTarget')

            if mode == 'attachPoint':

                class follicleAttach(cgmDrag.clickMesh):
                    def release_post_insert(self):
                        _str_funcName = 'follicleAttach.release'
                        """if not self.b_dragStoreMode:#If not on drag, do it here. Otherwise do it on update
                            if self._posBuffer:
                                self.l_return.extend(self._posBuffer)
                                if self._posBufferRaw:
                                    self.l_returnRaw.extend(self._posBufferRaw)
                                else:
                                    self.l_returnRaw.extend(self._posBuffer)
                        
                            if self._createModeBuffer:
                                self.l_created.extend(self._createModeBuffer)"""

                        for pos in self.l_returnRaw:
                            log.debug("|{0}|...pos {1}".format(
                                _str_funcName, pos))
                            for i, m in enumerate(self.d_meshPos.keys()):
                                log.debug("|{0}|...mesh: {1}".format(
                                    _str_funcName, m))
                                for i2, h in enumerate(self.d_meshPos[m]):
                                    if h == pos:
                                        log.debug("Found follicle match!")
                                        try:
                                            _set = [
                                                m, self.d_meshUV[m][i2],
                                                "{0}_u{1}_v{2}".format(
                                                    coreNames.get_short(m),
                                                    "{0:.4f}".format(
                                                        self.d_meshUV[m][i2]
                                                        [0]), "{0:.4f}".format(
                                                            self.d_meshUV[m]
                                                            [i2][1]))
                                            ]
                                            self._l_folliclesToMake.append(
                                                _set)
                                            log.debug("|{0}|...uv {1}".format(
                                                _str_funcName, _set))
                                        except Exception, err:
                                            log.error(
                                                "|{0}| >> Failed to query uv for hit {2} on shape {2} | err:{1}"
                                                .format(
                                                    _str_funcName, err, pos,
                                                    m))
                            if self._l_folliclesToMake:
                                for f_dat in self._l_folliclesToMake:
                                    _follicle = NODES.add_follicle(
                                        f_dat[0], f_dat[2])
                                    log.debug(
                                        "|finalize| >> Follicle created: {0}".
                                        format(_follicle))
                                    ATTR.set(_follicle[0], 'parameterU',
                                             f_dat[1][0])
                                    ATTR.set(_follicle[0], 'parameterV',
                                             f_dat[1][1])
                                    mc.parent(_loc, _follicle[0])
                        mc.delete(self.l_created)
                        self.dropTool()

                follicleAttach()

            return _loc
        elif not _targets:
            raise ValueError, "Must have targets for mode: {0} | targets: {1}".format(
                mode, _targets)