Esempio n. 1
0
def get_constraintsByDrivingObject(node=None, driver = None, fullPath = False):
    """
    Get a list of constraints driving a node by the drivers of those constraints.
    node 1 is driven by 3 constraints. 2 of those constraints use our driver as a target.
    Those 2 will be returned.
    
    :parameters:
        node(str): node to query
        driver(str): driver to check against
        fullPath(bool): How you want list
    :returns
        list of constraints(list)
    """   
    _str_func = 'get_constraintsTo'
    
    node = VALID.mNodeString(node)
    
    driver = VALID.mNodeString(driver)
    _long = NAMES.long(driver)   
    log.debug("|{0}| >> node: {1} | target: {2}".format(_str_func,node, _long))             
    
    l_constraints = get_constraintsTo(node,True)
    _res = False
    
    if l_constraints:
        _res = []
        for c in l_constraints:
            targets = get_targets(c,True)
            log.debug("|{0}| >> targets: {1}".format(_str_func, targets))              
            if _long in targets:
                log.debug("|{0}| >> match found: {1}".format(_str_func, c))                  
                _res.append(c)
    if _res and not fullPath:
        return [NAMES.short(o) for o in _res]
    return _res   
Esempio n. 2
0
def get_constraintsTo(node=None,
                      fullPath=True,
                      typeFilter=None,
                      typeMask=None):
    """
    Get the constraints on a given node
    
    :parameters:
        node(str): node to query
        fullPath(bool): How you want list
    :returns
        list of constraints(list)
    """
    _str_func = 'get_constraintsTo'

    node = VALID.mNodeString(node)

    _res = mc.listRelatives(node, type='constraint', fullPath=fullPath) or []
    _res = LISTS.get_noDuplicates(_res)

    if typeFilter:
        typeFilter = VALID.listArg(typeFilter)

        for i, t in enumerate(typeFilter):
            if 'Constraint' not in t:
                typeFilter[i] = t + 'Constraint'

        log.debug(
            cgmGEN.logString_msg(_str_func,
                                 'typeFilter: {0}'.format(typeFilter)))
        _res_filter = []
        for o in _res:
            _type = VALID.get_mayaType(o)
            if _type in typeFilter:
                _res_filter.append(o)
        _res = _res_filter

    if typeMask:
        typeMask = VALID.listArg(typeMask)

        for i, t in enumerate(typeMask):
            if 'Constraint' not in t:
                typeMask[i] = t + 'Constraint'

        log.debug(
            cgmGEN.logString_msg(_str_func, 'typeMask: {0}'.format(typeMask)))

        for o in _res:
            _type = VALID.get_mayaType(o)
            if _type in typeMask:
                _res.remove(o)
                log.debug(
                    cgmGEN.logString_msg(_str_func, 'removing: {0}'.format(o)))

    if fullPath:
        return [NAMES.long(o) for o in _res]
    return _res
Esempio n. 3
0
def get_constraintsTo(node=None, fullPath = True):
    """
    Get the constraints on a given node
    
    :parameters:
        node(str): node to query
        fullPath(bool): How you want list
    :returns
        list of constraints(list)
    """   
    _str_func = 'get_constraintsTo'
    
    node = VALID.mNodeString(node)
    
    _res = mc.listRelatives(node,type='constraint',fullPath=fullPath) or []
    _res = LISTS.get_noDuplicates(_res)
    if fullPath:
        return [NAMES.long(o) for o in _res]
    return _res
Esempio n. 4
0
def get_targets(node=None, fullPath=True, select=False):
    """
    Get the constraints a given node drives
    
    :parameters:
        node(str): node to query

    :returns
        list of targets(list)
    """
    _str_func = 'get_targets'
    if node == None:
        _sel = mc.ls(sl=True, long=True)
        if _sel:
            node = _sel[0]
        else:
            raise ValueError, "|{0}| >> No node arg. None selected".format(
                _str_func)

    node = VALID.mNodeString(node)
    _type = VALID.get_mayaType(node)

    _call = _d_type_to_call.get(_type, False)
    if not _call:
        _to = get_constraintsTo(node, True)
        if _to:
            log.debug(
                "|{0}| >> Not a constraint node. Found contraints to. Returning first"
                .format(_str_func))
            return get_targets(_to[0], fullPath, select)

        raise ValueError, "|{0}| >> {1} not a known type of constraint. node: {2}".format(
            _str_func, _type, node)

    _res = _call(node, q=True, targetList=True)
    if select:
        mc.select(_res)
    if fullPath:
        return [NAMES.long(o) for o in _res]
    return _res
Esempio n. 5
0
def get_constraintsFrom(node=None,
                        fullPath=True,
                        typeFilter=None,
                        typeMask=None):
    """
    Get the constraints a given node drives
    
    :parameters:
        node(str): node to query
        fullPath(bool): How you want list

    :returns
        list of constraints(list)
    """
    _str_func = 'get_constraintsFrom'

    node = VALID.mNodeString(node)

    _res = mc.listConnections(node,
                              source=False,
                              destination=True,
                              skipConversionNodes=True,
                              type='constraint') or []

    _res = LISTS.get_noDuplicates(_res)
    #_l_objectConstraints = get(node)
    #for c in _l_objectConstraints:
    #if c in _res:_res.remove(c)

    if typeFilter:
        typeFilter = VALID.listArg(typeFilter)

        for i, t in enumerate(typeFilter):
            if 'Constraint' not in t:
                typeFilter[i] = t + 'Constraint'

        log.debug(
            cgmGEN.logString_msg(_str_func,
                                 'typeFilter: {0}'.format(typeFilter)))
        _res_filter = []
        for o in _res:
            _type = VALID.get_mayaType(o)
            if _type in typeFilter:
                _res_filter.append(o)
        _res = _res_filter

    if typeMask:
        typeMask = VALID.listArg(typeMask)

        for i, t in enumerate(typeMask):
            if 'Constraint' not in t:
                typeMask[i] = t + 'Constraint'

        log.debug(
            cgmGEN.logString_msg(_str_func, 'typeMask: {0}'.format(typeMask)))

        for o in _res:
            _type = VALID.get_mayaType(o)
            if _type in typeMask:
                _res.remove(o)
                log.debug(
                    cgmGEN.logString_msg(_str_func, 'removing: {0}'.format(o)))

    if fullPath:
        return [NAMES.long(o) for o in _res]
    return _res
Esempio n. 6
0
def siblings_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
        siblings(list)
    """
    _str_func = 'siblings_get'
    _node = VALID.mNodeString(node)

    _l_res = []
    _type = VALID.get_mayaType(_node)

    log.debug("|{0}| >> node: [{1}] | type: {2}".format(
        _str_func, _node, _type))

    if VALID.is_shape(_node):
        log.debug("|{0}| >> shape...".format(_str_func))
        _long = NAME.long(_node)
        for s in shapes_get(_node, True):
            if s != _long:
                _l_res.append(s)

    elif not VALID.is_transform(_node):
        log.debug("|{0}| >> not a transform...".format(_str_func))
        if VALID.is_component(_node):
            log.debug("|{0}| >> component...".format(_str_func))
            _comp = VALID.get_component(_node)
            log.debug("|{0}| >> component: {1}".format(_str_func, _comp))
            _comb = "{0}.{1}".format(_comp[1], _comp[0])
            for c in mc.ls("{0}.{1}[*]".format(_comp[1], _comp[2]),
                           flatten=True):
                if str(c) != _comb:
                    _l_res.append(c)
        else:
            _long = NAME.long(_node)
            log.debug("|{0}| >> something else...".format(_str_func))
            _l = mc.ls(type=_type)
            for o in _l:
                if NAME.long(o) != _long:
                    _l_res.append(o)
            #raise ValueError,"Shouldn't have arrived. node: [{0}] | type: {1}".format(_node,_type)
    elif parents_get(_node):
        log.debug("|{0}| >> parented...".format(_str_func))
        _long = NAME.long(_node)
        for c in children_get(parent_get(node), True):
            if c != _long:
                _l_res.append(c)
    else:
        log.debug("|{0}| >> root transform...".format(_str_func))
        l_rootTransforms = get_rootList()
        _short = NAME.short(_node)
        for o in l_rootTransforms:
            if o != _short and VALID.get_mayaType(o) == _type:
                _l_res.append(o)

    if not fullPath:
        return [NAME.short(o) for o in _l_res]
    return _l_res