Ejemplo n.º 1
0
def matchTarget_snap(obj=None,
                     move=True,
                     rotate=True,
                     boundingBox=False,
                     pivot='rp'):
    """
    Snap an object to it's match target
    
    :parameters:
        obj(str): Object to modify
        target(str): Target to match

    :returns
        success(bool)
    """
    _str_func = 'matchTarget_snap'

    _obj = VALID.objString(obj,
                           noneValid=False,
                           calledFrom=__name__ + _str_func + ">> validate obj")

    _target = ATTR.get_message(_obj, 'cgmMatchTarget', 'cgmMatchDat', 0)

    if not _target:
        raise ValueError, "|{0}| >> {1} has no cgmMatchTarget.".format(
            _str_func, NAMES.get_short(_obj))

    log.debug("|{0}| >> {1} snapping to: {2}.".format(_str_func,
                                                      NAMES.get_short(_obj),
                                                      _target[0]))

    go(obj, _target[0], move, rotate, pivot=pivot)
    return True

    _dict = POS.get_info(_target[0])

    #cgmGEN.log_info_dict(_dict)

    pos = _dict['position']

    if move:
        mc.move(pos[0], pos[1], pos[2], _obj, ws=True, rpr=True)
    if rotate:
        #if _dict.get('rotateOrder'):mc.xform(_obj, roo=_dict['rotateOrder'],p=True)
        if _dict.get('rotation'): mc.xform(_obj, ro=_dict['rotation'], ws=True)
        #if _dict.get('rotateAxis'):mc.xform(_obj, ra=_dict['rotateAxis'],p=True)

    return True
def color_override(value=None, context='selection', mType=None):
    """
    Get data for updating a transform
    
    :parameters
        self(instance): cgmMarkingMenu

    :returns
        info(dict)
    """
    _str_func = "color_override"
    if context is None:
        _context = cgmMeta.cgmOptionVar('cgmVar_contextTD',
                                        defaultValue='selection').value
    else:
        _context = context.lower()
    _l_context = get_list(_context, mType)
    _l_context.extend(get_list(_context, 'joint'))

    log.debug("|{0}| >> value: {1} | mType: {2} | context: {3}".format(
        _str_func, value, mType, _context))
    if not _l_context:
        raise ValueError, "|{0}| >> Nothing found in context. {1}".format(
            _str_func, context)

    for o in _l_context:
        try:
            RIGGING.override_color(o, value)
        except Exception, err:
            log.error(
                "|{0}| >> set fail. obj:{1} | value:{2} | error: {3} | {4}".
                format(_str_func, NAMES.get_short(o), value, err, Exception))
def set_attrs(self,
              attr=None,
              value=None,
              context='selection',
              mType=None,
              select=True):
    """
    Get data for updating a transform
    
    :parameters
        self(instance): cgmMarkingMenu

    :returns
        info(dict)
    """
    _str_func = "set_attr"
    _context = context.lower()
    _sl = mc.ls(sl=True)

    _l_context = get_list(_context, mType)
    log.debug(
        "|{0}| >> attr: {1} | value: {2} | mType: {3} | context: {4}".format(
            _str_func, attr, value, mType, _context))

    for o in _l_context:
        try:
            #log.debug("|{0}| >>  obj:{1} | attr:{2} | value:{3} ".format(_str_func,o,attr,value))
            ATTR.set(o, attr, value)
            #cgmMeta.cgmNode(o).__setattr__(attr,value)
        except Exception, err:
            log.error(
                "|{0}| >> set fail. obj:{1} | attr:{2} | value:{3} | error: {4} | {5}"
                .format(_str_func, NAMES.get_short(o), attr, value, err,
                        Exception))
Ejemplo n.º 4
0
def get_transform(node=None):
    """
    Get transform of given node
    
    :parameters:
        node(str): Object to check

    :returns
        status(bool)
    """
    _str_func = 'is_transform'
    _node = stringArg(node, False, _str_func)

    _l = get_component(node)
    if _l:
        _root = _l[1]
    else:
        _root = node

    if is_transform(_root):
        return _root
    if is_shape(_root):
        _buffer = mc.listRelatives(_root, parent=True, fullPath=True) or False
        if _buffer:
            return _buffer[0]
            return NAME.get_short(_buffer[0])
    return False
Ejemplo n.º 5
0
def get_all_parents(node=None, shortNames=True):
    """
    Get all the parents of a given node where the last parent is the top of the heirarchy
    
    :parameters:
        node(str): Object to check
        shortNames(bool): Whether you just want short names or long

    :returns
        parents(list)
    """
    _str_func = 'get_all_parents'
    _node = VALID.stringArg(node, False, _str_func)

    _l_parents = []
    tmpObj = node
    noParent = False
    while noParent == False:
        tmpParent = mc.listRelatives(tmpObj, allParents=True, fullPath=True)
        if tmpParent:
            if len(tmpParent) > 1:
                raise ValueError, "Resolve what to do with muliple parents...{0} | {1}".format(
                    node, tmpParent)
            _l_parents.append(tmpParent[0])
            tmpObj = tmpParent[0]
        else:
            noParent = True
    if shortNames:
        return [NAME.get_short(o) for o in _l_parents]
    return _l_parents
Ejemplo n.º 6
0
def parents_get(node=None, fullPath=True):
    """
    Get all the parents of a given node where the last parent is the top of the heirarchy
    
    :parameters:
        node(str): Object to check
        fullPath(bool): Whether you want long names or not

    :returns
        parents(list)
    """
    _str_func = 'parents_get'
    _node = VALID.mNodeString(node)

    _l_parents = []
    tmpObj = _node
    noParent = False
    while noParent == False:
        tmpParent = mc.listRelatives(tmpObj, allParents=True, fullPath=True)
        if tmpParent:
            if len(tmpParent) > 1:
                raise ValueError, "Resolve what to do with muliple parents...{0} | {1}".format(
                    _node, tmpParent)
            _l_parents.append(tmpParent[0])
            tmpObj = tmpParent[0]
        else:
            noParent = True
    if not fullPath:
        return [NAME.get_short(o) for o in _l_parents]
    return _l_parents
Ejemplo n.º 7
0
                    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])
Ejemplo n.º 8
0
def get_listPathTo(node, node2, fullPath=True):
    """
    Get the list path from one object to another
    
    :parameters:
        node(str): node to query
        node2(str): node to check against

    :returns
        status(bool)
    """
    _str_func = 'get_listPathTo'
    _node = VALID.mNodeString(node)
    _node2 = VALID.mNodeString(node2)

    _nodeLong = NAME.get_long(_node)

    _res = []
    if is_parentTo(_node, _node2):
        log.debug("|{0}| >> isParent mode".format(_str_func))
        _node2Long = NAME.get_long(_node2)
        l_parents = parents_get(_node2, True)

        self_index = l_parents.index(_nodeLong)
        l_parents = l_parents[:self_index + 1]

        log.debug("|{0}| >> index {1} | {2}".format(_str_func, self_index,
                                                    l_parents))

        l_parents.reverse()

        for o in l_parents:
            _res.append(o)
            if o == _node2Long:
                break
        _res.append(_node2Long)

    elif is_childTo(_node, _node2):
        log.debug("|{0}| >> isChild mode".format(_str_func))

        l_parents = parents_get(_node, True)
        #l_parents.reverse()
        _res.append(_nodeLong)
        for o in l_parents:
            _res.append(o)
            if o == _nodeLong:
                break
    else:
        return False

    if not fullPath:
        return [NAME.get_short(o) for o in _res]
    return _res
Ejemplo n.º 9
0
    def varBuffer_define(self, optionVar):
        _str_func = 'varBuffer_define'

        sel = mc.ls(sl=True, flatten=True) or []

        if not sel:
            log.error("|{0}| >> No selection found. Cannot define")
            return False

        optionVar.clear()

        for o in sel:
            optionVar.append(NAMES.get_short(o))
        return True