예제 #1
0
def checkLayersOverride(shape):
    """Ensure that required shaders are connected to alembicHolder"""
    required = []
    connected = []

    # find the shaders / displacement that are required
    layersOverride = cmds.getAttr("%s.layersOverride" % shape)
    if layersOverride:
        layersOverride = json.loads(layersOverride)
        for layer in layersOverride:
            if layersOverride[layer].has_key('shaders'):
                for k in layersOverride[layer]['shaders'].keys():
                    if not k in required:
                        required.append(k)

    shape_connections = cmds.listAttr("%s.shaders" % shape, multi=True)

    # go find the connected shaders
    if shape_connections:
        for con in shape_connections:
            connected_shader = cmds.listConnections("%s.%s" % (shape, con))[0]
            connected.append(connected_shader)

    port = len(connected)
    for req in required:
        if req not in connected:
            if cmds.objExists(req):
                cmds.connectAttr(req + ".message",
                                 shape + ".shaders[%i]" % port)
                port += 1
                message = 'Connected %s to %s' % (req, shape)
                MGlobal.displayInfo(message)
            else:
                message = "Missing shader : %s" % req
                MGlobal.displayWarning(message)
예제 #2
0
def checkShadersAssignation(shape):
    """Ensure that required shaders are connected to alembicHolder"""
    required = []
    connected = []

    # find the shaders / displacement that are required
    shadersAssignation = cmds.getAttr("%s.shadersAssignation" % shape)
    if shadersAssignation:
        shadersAssignation = json.loads(shadersAssignation)
        for shader in shadersAssignation.keys():
            if not shader in required:
                required.append(shader)

    shape_connections = cmds.listAttr("%s.shaders" % shape, multi=True)

    # go find the connected shaders
    if shape_connections:
        for con in shape_connections:
            connected_shader = cmds.listConnections("%s.%s" % (shape, con))[0]
            connected.append(connected_shader)

    port = len(connected)
    for req in required:
        if req not in connected:
            if cmds.objExists(req):
                cmds.connectAttr(req + ".message",
                                 shape + ".shaders[%i]" % port)
                port += 1
                message = 'Connected %s to %s' % (req, shape)
                MGlobal.displayInfo(message)
            else:
                message = "Missing shader : %s" % req
                MGlobal.displayWarning(message)
예제 #3
0
def exportObjectAsAssFile(location="", objectName=""):
    if objectName == "":
        MGlobal.displayWarning("No object exported!!!")
        return False

    else:
        cmds.select(objectName, r=True)
        cmds.file(location + "/" + objectName, type="mayaBinary", force=True, exportSelected=True)
        return True
예제 #4
0
def exportObjectAsMbFile(location="", objectName=""):
    if objectName == "":
        MGlobal.displayWarning("No object exported!!!")
        return False

    else:
        print(objectName)
        cmds.select(objectName, replace=True)
        cmds.file(location + "/" + objectName, exportSelected=True, type="mayaBinary", constructionHistory=False, force=True)
        return True
예제 #5
0
def exportObjectAsMbFile(location="", objectName=""):
    if objectName == "":
        MGlobal.displayWarning("No object exported!!!")
        return False

    else:
        print(objectName)
        cmds.select(objectName, replace=True)
        cmds.file(location + "/" + objectName, exportSelected=True, type="mayaBinary", constructionHistory=False, force=True)

        return True
def obj_exists(obj_name, attribute_name=None):

    full_name = obj_name
    if attribute_name:
        full_name = "{0}.{1}".format(full_name, attribute_name)

    if cmds.objExists(full_name):
        return True
    else:
        MGlobal.displayWarning("Object does not exist: {0}".format(full_name))
        return False
예제 #7
0
def exportObjectAsAssFile(location="", objectName=""):
    """
    export objects to ass file
    """
    if objectName == "":
        MGlobal.displayWarning("No object exported!!!")
        return False

    else:
        cmds.select(objectName, r=True)
        cmds.file(location + "/" + objectName,
                  type="mayaBinary",
                  force=True,
                  exportSelected=True)
        return True
예제 #8
0
파일: animation.py 프로젝트: zewt/pymel
def ikHandle(*args, **kwargs):
    """
    Modifications:
        - always converts to PyNodes in create mode, even though results are
          non-unique short names
    """
    from . import nodetypes
    from maya.OpenMaya import MGlobal

    res = cmds.ikHandle(*args, **kwargs)

    # unfortunately, ikHandle returns non-unique names... however, it
    # doesn't support a parent option - so we can just throw a '|' in front
    # of the first return result (the ikHandle itself) to get a unique name
    # We then need to track through it's connections to find the endEffector...

    if kwargs.get('query', kwargs.get('q', False)):
        if kwargs.get('endEffector', kwargs.get('ee', False)):
            res = _factories.toPyNode(res)
        elif kwargs.get('jointList', kwargs.get('jl', False)):
            res = _factories.toPyNodeList(res)
    elif (not kwargs.get('edit', kwargs.get('e', False))
          and isinstance(res, list) and len(res) == 2
          and all(isinstance(x, basestring) for x in res)):
        handleName, effectorName = res
        # ikHandle doesn't support a parent kwarg, so result should always be
        # grouped under the world...
        handleNode = _factories.toPyNode('|' + handleName)
        # unfortunately, effector location is a little harder to predict. but
        # can find it by following connections...
        effectorNode = handleNode.attr('endEffector').inputs()[0]
        if effectorNode.nodeName() == effectorName:
            res = [handleNode, effectorNode]
        else:
            MGlobal.displayWarning(
                "Warning: returned ikHandle %r was connected to effector %r, "
                "which did not match returned effector name %r" %
                (handleName, effectorNode.shortName(), effectorName))
    return res
예제 #9
0
def ikHandle(*args, **kwargs):
    """
    Modifications:
        - always converts to PyNodes in create mode, even though results are
          non-unique short names
    """
    import nodetypes
    from maya.OpenMaya import MGlobal

    res = cmds.ikHandle(*args, **kwargs)

    # unfortunately, ikHandle returns non-unique names... however, it
    # doesn't support a parent option - so we can just throw a '|' in front
    # of the first return result (the ikHandle itself) to get a unique name
    # We then need to track through it's connections to find the endEffector...

    if kwargs.get('query', kwargs.get('q', False)):
        if kwargs.get('endEffector', kwargs.get('ee', False)):
            res = _factories.toPyNode(res)
        elif kwargs.get('jointList', kwargs.get('jl', False)):
            res = _factories.toPyNodeList(res)
    elif (not kwargs.get('edit', kwargs.get('e', False))
            and isinstance(res, list) and len(res) == 2
            and all(isinstance(x, basestring) for x in res)):
        handleName, effectorName = res
        # ikHandle doesn't support a parent kwarg, so result should always be
        # grouped under the world...
        handleNode = _factories.toPyNode('|' + handleName)
        # unfortunately, effector location is a little harder to predict. but
        # can find it by following connections...
        effectorNode = handleNode.attr('endEffector').inputs()[0]
        if effectorNode.nodeName() == effectorName:
            res = [handleNode, effectorNode]
        else:
            MGlobal.displayWarning(
                "Warning: returned ikHandle %r was connected to effector %r, "
                "which did not match returned effector name %r"
                % (handleName, effectorNode.shortName(), effectorName))
    return res
예제 #10
0
def cmdWarn(info):
    from maya.OpenMaya import MGlobal
    MGlobal.displayWarning('%s' % (info))