예제 #1
0
def export_lightlinks():
    
    raw_name, extension = os.path.splitext(cmds.file(q=True, sn=True, shn=True))
    if raw_name == "":
        filename = "untitled"
    else:
        filename = raw_name
    filepath = "{0}{1}.llink".format(cmds.workspace(q=True, rootDirectory=True),filename)
        
    lights = cmds.ls(type=["light"] + cmds.listNodeTypes("light"))
    
    shapeList = cmds.ls(objectsOnly=True, type="mesh" )
    transformList = cmds.listRelatives(shapeList, parent=True,)
    grouplist = cmds.listRelatives(transformList, parent=True)
    
    lightlinkobjectlist = shapeList + transformList + grouplist + cmds.ls(objectsOnly=True, type="objectSet") + cmds.ls(objectsOnly=True, type="shadingEngine" )
    
    lightlinks = {}
    for light in lights:
        links = cmds.lightlink( query=True, light=light)
        lightlinks.update( {light : list(links)} )
        
        #### breakmap
        lightbreakups = set(lightlinkobjectlist) - set(cmds.lightlink( query=True, light=light)) - {"defaultLightSet", "defaultObjectSet"}
    
        if list(lightbreakups) == []:
            lightbreakups = "none"
            lightlinks.update( {light + "_breakup" : lightbreakups} )
        else:
            lightlinks.update( {light + "_breakup" : list(lightbreakups)} )
          
    with open(filepath, 'w') as json_file:
      json.dump(lightlinks, json_file, indent=4, sort_keys=True)
    print "lightlinks exported to {0}".format(filepath)
예제 #2
0
def select_attached(shadow_link=False):
    selection = cmds.ls(dag=1, o=1, s=1, sl=1)
    lights = cmds.ls(selection, type=["light"] + cmds.listNodeTypes("light"))
    selection = cmds.pickWalk(direction='down')

    if not selection and not lights: return "error:no_light_selection"

    attached_objs = []

    if lights:
        for sel in selection:
            attached_objs += cmds.lightlink(query=True,
                                            shadow=shadow_link,
                                            light=sel)
        select_nodes = cmds.ls(attached_objs, type=['mesh', 'nurbsSurface'])
    else:  # MESHES
        for sel in selection:
            attached_objs += cmds.lightlink(query=True,
                                            shadow=shadow_link,
                                            object=selection)
        select_nodes = cmds.ls(attached_objs,
                               type=["light"] + cmds.listNodeTypes("light"))

    if not select_nodes: return
    cmds.select(select_nodes)
    cmds.pickWalk(direction='up')
예제 #3
0
def remove_all_lightlinking():
    all_objects = mc.ls(type='transform')
    all_lights = get_lights()
    for shadow in [True, False]:
        mc.lightlink(light=all_lights,
                     object=all_objects,
                     b=True,
                     shadow=shadow)
예제 #4
0
def _CleanUp(lightName, lightType, lightT, lightR, lightS, lightLinked):
    if cmds.objExists('LIGHTS_hrc') != True:
        cmds.group(name='LIGHTS_hrc', empty=True)
    
    if cmds.objExists(lightName):
        if cmds.objectType(lightName) == lightType:
            lightSucced = 1
            newLight = cmds.listRelatives(lightName, parent=True)[0]
        else:
            lightSucced = 0
            print "%s is not %s type of light, so information wont transfer"%(lightName,lightType)
    else:
        lightSucced = 1
        if lightType == 'ambientLight':
            cmds.rename(cmds.CreateAmbientLight(1, 0.45, 1,1,1, "0", 0,0,0, "1"),lightName)
            newLight = cmds.rename(lightName,lightName.replace('Shape',''))
            cmds.rename(cmds.listRelatives(newLight, children=True)[0],lightName)
        elif lightType == 'directionalLight':
            cmds.rename(cmds.CreateDirectionalLight(1, 1,1,1, "0", 0,0,0, 0),lightName)
            newLight = cmds.rename(lightName,lightName.replace('Shape',''))
            cmds.rename(cmds.listRelatives(newLight, children=True)[0],lightName)
        elif lightType == 'pointLight':
            cmds.rename(cmds.CreatePointLight(1, 1,1,1, 0, 0, 0,0,0, 1),lightName)
            newLight = cmds.rename(lightName,lightName.replace('Shape',''))
            cmds.rename(cmds.listRelatives(newLight, children=True)[0],lightName)
        elif lightType == 'spotLight':
            cmds.rename(cmds.CreateSpotLight(1, 1,1,1, 0, 40, 0, 0, 0, 0,0,0, 1, 0),lightName)
            newLight = cmds.rename(lightName,lightName.replace('Shape',''))
            cmds.rename(cmds.listRelatives(newLight, children=True)[0],lightName)
        elif lightType == 'areaLight':
            cmds.rename(cmds.CreateAreaLight(1, 1,1,1, 0, 0, 0,0,0, 1, 0),lightName)
            newLight = cmds.rename(lightName,lightName.replace('Shape',''))
            cmds.rename(cmds.listRelatives(newLight, children=True)[0],lightName)
        elif lightType == 'volumeLight':
            cmds.rename(cmds.CreateVolumeLight(1, 1,1,1, 0, 0, 0,0,0, 1),lightName)
            newLight = cmds.rename(lightName,lightName.replace('Shape',''))
            cmds.rename(cmds.listRelatives(newLight, children=True)[0],lightName)

#         newLight = cmds.createNode(lightType)
#         newLight = cmds.rename(newLight,lightName)
#         newLight = cmds.rename(cmds.listRelatives(newLight, parent=True)[0],lightName.replace('Shape',''))

    cmds.xform(newLight, translation=lightT,rotation=lightR,scale=lightS)

    if cmds.listRelatives('LIGHTS_hrc', children=True) == None or newLight not in cmds.listRelatives('LIGHTS_hrc', children=True):
        cmds.parent(newLight,'LIGHTS_hrc')
    
    everything = cmds.ls()
    cmds.lightlink(b=True,light=lightName,object=everything)
    if lightLinked != "":
        for eachAsset in lightLinked:
            try:
    #             time.sleep(1)
                cmds.lightlink(light=lightName,object=eachAsset)
            except:
#                 print eachAsset
                pass
    return lightSucced
예제 #5
0
def set_lightlinking_from_dict(lightlinking):
    remove_all_lightlinking()
    for light in lightlinking:
        print(light)
        for shadow in lightlinking[light]:
            objects = lightlinking[light][shadow]
            count = len(objects)
            objects = mc.ls(objects)
            if len(objects) != count:
                print('Missing %i objects' % (count - len(objects)))
            mc.lightlink(make=True, light=light, object=objects, shadow=shadow)
예제 #6
0
	def importLightLinking(self, asset = '', searchAndReplace = ['',''] ):
		"""import light linking to lights"""
		LayersInfo = pickle.load( open( self.lightLinkPath.path, "rb") )
		mc.refresh( su = 1 )
		if not asset == '':
			LayersInfo = self.filterLightLinksData( LayersInfo , asset, searchAndReplace )
		for l in LayersInfo.keys():
			objsToBreakLink = []
			for link in LayersInfo[l]:
				if mc.objExists( link ):
					objsToBreakLink.append( link )
			mc.lightlink( b = True, light = l, o = objsToBreakLink )
		mc.refresh( su = 0 )
예제 #7
0
	def exportLightLinking(self):
		"""export all the lightlinking in the scene"""
		lights    = [a for a in mc.ls( typ = ['light','aiAreaLight'] ) if not 'eye' in a]
		allShapes = [s for s in mc.ls( type = 'geometryShape', ni = 1) if not (mc.objectType( s ) in ( 'aiAreaLight','aiSkyDomeLight' ))]
		litLinks  = {}
		for l in lights:
			lightLinkShapes = mc.lightlink( query=True, light=l ,shp=1,t=0,set=0,h=0)
			litLinks[l]	    = list( set( allShapes ) - set( lightLinkShapes ) )#SHAPES WITH NO LINK TO THIS LIGHT
		pickle.dump( litLinks, open( self.lightLinkPath.path, "wb" ) )
예제 #8
0
def get_lightlinking_as_dict():
    lightlinking = {}
    for light in get_lights():
        light_ll = {}
        for shadow in [False, True]:
            light_ll[shadow] = mc.lightlink(query=True,
                                            light=light,
                                            shadow=shadow)
        lightlinking[light] = light_ll
    return lightlinking
예제 #9
0
    def _lightLinkSets(self):
        debug(app = self, method = '_lightLinkSets', message = 'Light Linking Sets...', verbose = False)

        conn = cmds.listConnections('lightLinker1', connections= True, plugs = True)
        allConn = zip(conn[::2], conn[1::2])
        for each in allConn:
            if 'initialParticleSE' not in each[1] and 'defaultLightSet' not in each[1] and 'initialShadingGroup' not in each[1]:
                cmds.disconnectAttr(each[1],each[0])
    
    
        cmds.select(clear = True)
        allSets = cmds.listSets(allSets= True)
        for each in allSets:
            if each[:10] == 'LightLink_':
                lightName = each[10:]
                lightSet  = each
                cmds.select(lightName, lightSet, replace = True, noExpand = True)
                cmds.lightlink(make =True, useActiveLights = True, useActiveObjects = True)
    
        cmds.select(clear = True)
예제 #10
0
    def relinkLit(self, info):
        '''
		Relink lights with information.
		'''

        for lit in info.keys():
            # Break current light links.
            ilObjLs = cmds.ls(cmds.lightlink(query=True, light=lit),
                              type='mesh')
            cmds.lightlink(b=True, light=lit, object=ilObjLs)

            # Get object list linked to light from saved information.
            litLinkObjLs = info[lit]
            for litLinkObj in litLinkObjLs:
                try:
                    # Make light link to each shape.
                    cmds.lightlink(make=True, light=lit, object=litLinkObj)
                except:
                    OpenMaya.MGlobal.displayWarning(
                        "%s is not exists.\n Can't be linked with %s." %
                        (litLinkObj, lit))
예제 #11
0
def copy_asset_lightlinking(source_namespace, target_namespace):
    for light in get_lights():
        target_nodes = mc.ls(target_namespace + ':*', type='mesh')
        for shadow in [False, True]:
            mc.lightlink(light=light,
                         object=target_nodes,
                         b=True,
                         shadow=shadow)
            for node in mc.lightlink(query=True, light=light, shadow=shadow):
                if mc.nodeType(node) != 'mesh':
                    continue
                if source_namespace not in node:
                    continue
                target_node = node.replace(source_namespace, target_namespace)
                if not mc.objExists(target_node):
                    continue
                print(node, target_node)
                mc.lightlink(make=True,
                             light=light,
                             object=target_node,
                             shadow=shadow)
예제 #12
0
    def getSceneLitLnkInfo(self):
        '''
		Get current scene light links information.
		'''

        litLinkTable = {}

        litLs = cmds.ls(type='light')
        if litLs:
            for lit in litLs:
                ilObjLs = cmds.ls(cmds.lightlink(query=True, light=lit),
                                  type='mesh')
                litLinkTable[lit] = ilObjLs

        return litLinkTable
예제 #13
0
 def showLinkedObjects(self):
     lightName = self.getSelected()
     print lightName
     if len(lightName) < 1:
         cmds.confirmDialog(title='Error',
                            message='Please select a light',
                            button=['Ok'],
                            defaultButton='Ok',
                            cancelButton='Ok',
                            dismissString='Ok')
         print "Please select a light"
         pass
     else:
         objectsLinked = cmds.lightlink(q=True, light=lightName, sets=False)
         if objectsLinked:
             cmds.select(objectsLinked, replace=True)
예제 #14
0
def selection_light_linking(break_light=False,
                            exclusive="",
                            shadow_link=False):
    selection = cmds.ls(dag=1, o=1, s=1, sl=1)
    lights = cmds.ls(selection, type=["light"] + cmds.listNodeTypes("light"))
    meshes = list(set(selection) - set(lights))

    if not selection or not lights: return "error:no_light_selection"

    if exclusive == "lights":
        scene_lights = cmds.ls(type=["light"] + cmds.listNodeTypes("light"))
        exclude_lights = list(set(scene_lights) - set(lights))
        cmds.lightlink(light=exclude_lights,
                       object=meshes,
                       shadow=shadow_link,
                       b=True)

        LOG.info("exclude_lights: {}".format(exclude_lights))

    elif exclusive == "meshes":
        exclude_meshes = list(set(cmds.ls(dag=1, o=1, s=1)) - set(meshes))
        cmds.lightlink(light=lights,
                       object=exclude_meshes,
                       shadow=shadow_link,
                       b=True)

        LOG.info("exclude_meshes: {}".format(exclude_meshes))

    if not meshes:
        cmds.lightlink(light=lights,
                       object=cmds.ls(dag=1, o=1, s=1),
                       shadow=shadow_link)
        LOG.info("LightLinking: Default for {}".format(lights))
        return

    cmds.lightlink(light=lights,
                   object=meshes,
                   shadow=shadow_link,
                   b=break_light)
    LOG.debug("LightLinking - break:{} - shadow:{}: {} with {}".format(
        break_light, shadow_link, lights, meshes))
def _RecordLight():
    '''
    lightDict {[LIGHT NAME]:
                        [TYPE OF LIGHT]:
                                [VALUE]
                        [LINKS]:
                                [VALUE]
                        [TRANSLATE]
                                [VALUE]
                        [ROTATION]
                                [VALUE]
                        [SCALE]
                                [VALUE]}
    '''
    allTheLights = []
    typeLists = ['directionalLight','volumeLight','areaLight','spotLight','pointLight','ambientLight']
    for eachType in typeLists:
        allTheLights += cmds.ls(exactType = eachType)

    lightDict = {}
    if allTheLights:
        for eachLight in allTheLights:
            generalDict = {}
            for eachType in typeLists:
                if cmds.nodeType(eachLight) == eachType:
                    generalDict["Type"]         = eachType #Getting the Type of Light
                    lightLinkedList = []
                    eachLightT = cmds.listRelatives(eachLight, parent=True)[0]
                    for eachLink in cmds.lightlink(query=True, light=eachLight):
                        print eachLink
                        lightLinkedList.append(str(eachLink))
                    generalDict["Linked"]       = lightLinkedList #Getting the list of objects linked to
                    lightTranslation = cmds.xform(eachLightT,query = True, translation=True) 
                    generalDict["Translation"]  = lightTranslation #GEtting the Translation
                    lightRotation = cmds.xform(eachLightT,query = True, rotation=True) 
                    generalDict["Rotation"]     = lightRotation #Getting the Rotation
                    lightScale = cmds.xform(eachLightT,query = True, scale=True, relative=True) 
                    generalDict["Scale"]        = lightScale #Getting the Scale
            lightDict[eachLight] = generalDict
    
    print "Generation Light is Done"
    return lightDict
예제 #16
0
def _RecordLight():
    '''
    lightDict {[LIGHT NAME]:
                        [TYPE OF LIGHT]:
                                [VALUE]
                        [LINKS]:
                                [VALUE]
                        [TRANSLATE]
                                [VALUE]
                        [ROTATION]
                                [VALUE]
                        [SCALE]
                                [VALUE]}
    '''
    allTheLights = []
    typeLists = ['directionalLight','volumeLight','areaLight','spotLight','pointLight','ambientLight']
    for eachType in typeLists:
        allTheLights += cmds.ls(exactType = eachType)

    lightDict = {}
    if allTheLights:
        for eachLight in allTheLights:
            generalDict = {}
            for eachType in typeLists:
                if cmds.nodeType(eachLight) == eachType:
                    generalDict["Type"]         = eachType #Getting the Type of Light
                    lightLinkedList = []
                    eachLightT = cmds.listRelatives(eachLight, parent=True)[0]
                    for eachLink in cmds.lightlink(query=True, light=eachLight):
                        print eachLink
                        lightLinkedList.append(str(eachLink))
                    generalDict["Linked"]       = lightLinkedList #Getting the list of objects linked to
                    lightTranslation = cmds.xform(eachLightT,query = True, translation=True) 
                    generalDict["Translation"]  = lightTranslation #GEtting the Translation
                    lightRotation = cmds.xform(eachLightT,query = True, rotation=True) 
                    generalDict["Rotation"]     = lightRotation #Getting the Rotation
                    lightScale = cmds.xform(eachLightT,query = True, scale=True, relative=True) 
                    generalDict["Scale"]        = lightScale #Getting the Scale
            lightDict[eachLight] = generalDict
    
    print "Generation Light is Done"
    return lightDict
예제 #17
0
 def makeCB(*args):
     cmds.lightlink(make=True, light=node, useActiveObjects=True)
예제 #18
0
    def _createAllLights(self, XMLPath = '', Namespace = '' , Root = ''):
        debug(app = self, method = '_createAllLights', message = '_createAllLights...', verbose = False)
        
        # If the namespace doesn't exist, the objects wont get named correctly create the namespace
        if Namespace != "" and Namespace != ":":
            if not cmds.namespace( exists= Namespace[:-1] ):
                cmds.namespace( add = Namespace[:-1])

        typeShader      = cmds.listNodeTypes( 'shader' ) or []
        typeTexture     = cmds.listNodeTypes( 'texture' ) or []
        typeUtility     = cmds.listNodeTypes( 'utility' ) or []
        typeMRTexture   = cmds.listNodeTypes( 'rendernode/mentalray/texture' ) or []
        typeMRDisp      = cmds.listNodeTypes( 'rendernode/mentalray/displace' ) or []
        typeMREnv       = cmds.listNodeTypes( 'rendernode/mentalray/environment' ) or []
        typeMRLightMaps = cmds.listNodeTypes( 'rendernode/mentalray/lightmap' ) or []
        typeMRMisc      = cmds.listNodeTypes( 'rendernode/mentalray/misc' ) or []
        typeMRConv      = cmds.listNodeTypes( 'rendernode/mentalray/conversion') or []
        typeMRInternal  = cmds.listNodeTypes( 'rendernode/mentalray/internal') or []
        typeMRGeometry  = cmds.listNodeTypes( 'rendernode/mentalray/geometry') or []
    
        typeLights      = cmds.listNodeTypes( 'light' ) or []
        typeMRLights    = cmds.listNodeTypes( 'rendernode/mentalray/light' ) or []
        typeMRLens      = cmds.listNodeTypes( 'rendernode/mentalray/lens' ) or []
    
        debug(app = self, method = '_createAllLights', message = 'Processed lists...', verbose = False)
        # get the root of the XMLPath argument
        root = xml.parse(XMLPath).getroot()
    
        # Create an iterator based on the the root argument
        shaderIterator = root.getiterator(Root)
        # Iterate on shader level
        for levelOne in shaderIterator:
            # Iterate on parent tag level
            if levelOne.getchildren():
                for levelTwo in levelOne:
                    if levelTwo.tag == 'Nodes':
                        debug(app = self, method = '_createAllLights', message = 'Building Nodes...', verbose = False)

                        for levelThree in levelTwo.getchildren():
                            node_name = levelThree.tag
                            debug(app = self, method = '_createAllLights', message = 'node_name:%s' % node_name, verbose = False)

                            if '_cCc_' in node_name:
                                node_name = node_name.replace('_cCc_', ':')
                            node_name = Namespace + node_name
                            node_type = levelThree.attrib['value']
                            debug(app = self, method = '_createAllLights', message = 'node_type:%s' % node_type, verbose = False)
    
                            # Create all node types and sort them into correct hypershade tabs
                            try:
                                if node_type in typeLights or node_type in typeMRLights:
                                    debug(app = self, method = '_createAllLights', message = 'node_type:%s is in typeLights or typeMRLights' % node_type, verbose = False)
                                    if not self.doesAssetAlreadyExistInScene(node_name):
                                        cmds.shadingNode(node_type, asLight = True , name = node_name)
                            except:
                                pass
    
                            try:
                                if node_type in typeTexture or node_type in typeMRTexture:
                                    debug(app = self, method = '_createAllLights', message = 'node_type:%s is in typeTexture or typeMRTexture' % node_type, verbose = False)
                                    if not self.doesAssetAlreadyExistInScene(node_name):
                                        cmds.shadingNode(node_type, asTexture = True , name = node_name)
                            except:
                                pass
    
                            try:
                                if node_type in typeUtility:
                                    debug(app = self, method = '_createAllLights', message = 'node_type:%s is in typeUtility' % node_type, verbose = False)
                                    if not self.doesAssetAlreadyExistInScene(node_name):
                                        cmds.shadingNode(node_type, asUtility = True , name = node_name)
                            except:
                                pass
    
                            try:
                                if node_type in typeMREnv or node_type in typeMRLightMaps or node_type in typeMRMisc or node_type in typeMRConv or node_type in typeMRDisp or node_type in typeMRInternal or node_type in typeMRGeometry or node_type in typeMRLens:
                                    debug(app = self, method = '_createAllLights', message = 'node_type:%s is in typeMREnv, typeMRLightMaps, typeMRMisc, typeMRConv, typeMRDisp, typeMRInternal, typeMRGeometry, typeMRLens' % node_type, verbose = False)
                                    if not self.doesAssetAlreadyExistInScene(node_name):
                                        cmds.createNode( node_type, ss=True, name = node_name)
                            except:
                                pass
    
    
                    if levelTwo.tag == 'Attributes':
                        debug(app = self, method = '_createAllLights', message = 'levelTwo.tag: Assigning Attributes...', verbose = False)

                        for attributes in levelTwo.getchildren():
                            attrNode = attributes.tag
                            attrNode = Namespace + attrNode
                            if '_aAa_' in attrNode:
                                attrNode = attrNode.replace('_aAa_', '[')
                                attrNode = attrNode.replace('_zZz_', ']')
                            if '_cCc_' in attrNode:
                                attrNode = attrNode.replace('_cCc_', ':')
                            if '_tTt_' in attrNode:
                                attrNode = attrNode.replace('_tTt_', '+')
                            if '_mMm_' in attrNode:
                                attrNode = attrNode.replace('_mMm_', '-')
                            attrValue =  attributes.attrib['value']
    
                            if '.illuminatesDefault' in attrNode:
                                if attrValue == '0.0':
                                    lightName = attrNode.split('.')
                                    lightName = lightName[0]
                                    lightParent = cmds.listRelatives(lightName, parent = True)
                                    lightParent = lightParent[0]
                                    for x in range(30):
                                        try:
                                            cmds.disconnectAttr(lightParent + '.instObjGroups[0]','defaultLightSet.dagSetMembers[%i]' %x)
                                        except:
                                            pass
    
    
                            try:
                                cmds.setAttr(attrNode, float(attrValue), lock = False)
                            except:
                                pass
                            try:
                                cmds.setAttr(attrNode, str(attrValue), type = 'string', lock = False)
                            except:
                                pass
                            try:
                                cmds.setAttr(attrNode, str(attrValue), type = 'double3', lock = False)
                            except:
                                pass
    
                    if levelTwo.tag == 'LightLinking':
                        debug(app = self, method = '_createAllLights', message = 'levelTwo.tag: Light Linking Objects...', verbose = False)

                        cmds.select(clear = True)
                        for levelThree in levelTwo.getchildren():
                            set_name = levelThree.tag
                            cmds.select(clear = True)
                            createSet = cmds.sets( name = set_name )
                            LightName = set_name.split('LightLink_')
                            LightName = LightName[1]
                            for levelFour in levelThree.getchildren():
                                objectName = levelFour.tag
                                objectName = objectName.replace('_cCc_', ':')
                                try:
                                    cmds.select(objectName, replace = True)
                                    cmds.sets(objectName, edit = True, addElement = createSet)
                                except:
                                    debug(app = self, method = '_createAllLights', message = 'MISSING OBJECT: %s' % objectName, verbose = False)
#                                     cmds.warning('\nSome objects not present in the scene, cannot light link.\n')
#                                     print '* Missing Object * : \t' + objectName
                                    pass
                            cmds.select(clear = True)
                            cmds.select(LightName, createSet, noExpand = True, replace = True)
                            cmds.lightlink(make = True, useActiveLights = True, useActiveObjects = True)
                            debug(app = self, method = '_createAllLights', message = 'Success light linking something...', verbose = False)
        debug(app = self, method = '_createAllLights', message = 'FINISHED', verbose = False)
예제 #19
0
파일: _rsLight.py 프로젝트: WuLiFang/Maya
def breakAllLightLink():
    light = ls(selection=True)[0]
    lightlink(b=True, light=light, object=lightlink(query=True, object=light))
예제 #20
0
 def setLinkedObjects(self):
     lightName = self.getSelected()
     objectsLinked = cmds.lightlink(q=True, light=lightName, sets=False)
     cmds.lightlink(b=True, light=lightName, object=objectsLinked)
     objectsLinked = cmds.ls(selection=True, type=('transform', 'shape'))
     cmds.lightlink(light=lightName, object=objectsLinked)
예제 #21
0
def linkLights():
    cmds.lightlink(b=True, light=selectedLights, object=allDeselectedObjects)
    cmds.lightlink(light=selectedLights, object=selectedObjects)
예제 #22
0
def _CleanUp(lightName, lightType, lightT, lightR, lightS, lightLinked):
    if cmds.objExists('LIGHTS_hrc') != True:
        cmds.group(name='LIGHTS_hrc', empty=True)

    if cmds.objExists(lightName):
        if cmds.objectType(lightName) == lightType:
            lightSucced = 1
            newLight = cmds.listRelatives(lightName, parent=True)[0]
        else:
            lightSucced = 0
            print "%s is not %s type of light, so information wont transfer" % (
                lightName, lightType)
    else:
        lightSucced = 1
        if lightType == 'ambientLight':
            cmds.rename(
                cmds.CreateAmbientLight(1, 0.45, 1, 1, 1, "0", 0, 0, 0, "1"),
                lightName)
            newLight = cmds.rename(lightName, lightName.replace('Shape', ''))
            cmds.rename(
                cmds.listRelatives(newLight, children=True)[0], lightName)
        elif lightType == 'directionalLight':
            cmds.rename(
                cmds.CreateDirectionalLight(1, 1, 1, 1, "0", 0, 0, 0, 0),
                lightName)
            newLight = cmds.rename(lightName, lightName.replace('Shape', ''))
            cmds.rename(
                cmds.listRelatives(newLight, children=True)[0], lightName)
        elif lightType == 'pointLight':
            cmds.rename(cmds.CreatePointLight(1, 1, 1, 1, 0, 0, 0, 0, 0, 1),
                        lightName)
            newLight = cmds.rename(lightName, lightName.replace('Shape', ''))
            cmds.rename(
                cmds.listRelatives(newLight, children=True)[0], lightName)
        elif lightType == 'spotLight':
            cmds.rename(
                cmds.CreateSpotLight(1, 1, 1, 1, 0, 40, 0, 0, 0, 0, 0, 0, 1,
                                     0), lightName)
            newLight = cmds.rename(lightName, lightName.replace('Shape', ''))
            cmds.rename(
                cmds.listRelatives(newLight, children=True)[0], lightName)
        elif lightType == 'areaLight':
            cmds.rename(cmds.CreateAreaLight(1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0),
                        lightName)
            newLight = cmds.rename(lightName, lightName.replace('Shape', ''))
            cmds.rename(
                cmds.listRelatives(newLight, children=True)[0], lightName)
        elif lightType == 'volumeLight':
            cmds.rename(cmds.CreateVolumeLight(1, 1, 1, 1, 0, 0, 0, 0, 0, 1),
                        lightName)
            newLight = cmds.rename(lightName, lightName.replace('Shape', ''))
            cmds.rename(
                cmds.listRelatives(newLight, children=True)[0], lightName)


#         newLight = cmds.createNode(lightType)
#         newLight = cmds.rename(newLight,lightName)
#         newLight = cmds.rename(cmds.listRelatives(newLight, parent=True)[0],lightName.replace('Shape',''))

    cmds.xform(newLight, translation=lightT, rotation=lightR, scale=lightS)

    if cmds.listRelatives(
            'LIGHTS_hrc',
            children=True) == None or newLight not in cmds.listRelatives(
                'LIGHTS_hrc', children=True):
        cmds.parent(newLight, 'LIGHTS_hrc')

    everything = cmds.ls()
    cmds.lightlink(b=True, light=lightName, object=everything)
    if lightLinked != "":
        for eachAsset in lightLinked:
            try:
                #             time.sleep(1)
                cmds.lightlink(light=lightName, object=eachAsset)
            except:
                #                 print eachAsset
                pass
    return lightSucced
예제 #23
0
 def breakCB(*args):
     cmds.lightlink(b=True, light=node, useActiveObjects=True)
예제 #24
0
    def xferAttrs(self):
        if self.Node1Type == "transform":
            if "Shape" in self.nodeOne:
                xformNode1 = cmds.listRelatives(self.nodeOne, parent=True)
                shapeNode1 = self.nodeOne
                xformNode1 = xformNode1[0]
            if "Shape" not in self.nodeOne:
                xformNode1 = cmds.listRelatives(self.nodeOne, children=True)
                shapeNode1 = xformNode1[0]
                xformNode1 = self.nodeOne
            if "Shape" in self.nodeTwo:
                xformNode2 = cmds.listRelatives(self.nodeTwo, parent=True)
                shapeNode2 = self.nodeTwo
                xformNode2 = xformNode2[0]
            if "Shape" not in self.nodeTwo:
                xformNode2 = cmds.listRelatives(self.nodeTwo, children=True)
                shapeNode2 = xformNode2[0]
                xformNode2 = self.nodeTwo

            self.XformNodeType = cmds.nodeType(xformNode1) or []
            self.shapeNodeType = cmds.nodeType(shapeNode1) or []

            if self.XformNodeType == "transform" and self.shapeNodeType == "mesh":
                attrsRem_xform = [
                    "message", "hyperLayout", "borderConnections",
                    "publishedNodeInfo.publishedNode",
                    "publishedNodeInfo.isHierarchicalNode",
                    "publishedNodeInfo.publishedNodeType", "boundingBox",
                    "instObjGroups",
                    "instObjGroups.objectGroups.objectGrpCompList",
                    "instObjGroups.objectGroups.objectGroupId",
                    "instObjGroups.objectGroups.objectGrpColor",
                    "drawOverride", "renderLayerInfo.renderLayerId",
                    "renderLayerInfo.renderLayerRenderable",
                    "renderLayerInfo.renderLayerColor", "ghostDriver",
                    "rotatePivot", "scalePivot", "rotateAxis", "selectHandle",
                    "rotateQuaternion"
                ]
                attrsRem_shape = [
                    "message", "hyperLayout", "borderConnections",
                    "publishedNodeInfo.publishedNode",
                    "publishedNodeInfo.isHierarchicalNode",
                    "publishedNodeInfo.publishedNodeType", "boundingBox",
                    "instObjGroups",
                    "instObjGroups.objectGroups.objectGrpCompList",
                    "instObjGroups.objectGroups.objectGroupId",
                    "instObjGroups.objectGroups.objectGrpColor",
                    "drawOverride", "renderLayerInfo.renderLayerId",
                    "renderLayerInfo.renderLayerRenderable",
                    "renderLayerInfo.renderLayerColor", "ghostDriver",
                    "referenceObject", "compInstObjGroups",
                    "compInstObjGroups.compObjectGroups.compObjectGrpCompList",
                    "compInstObjGroups.compObjectGroups.compObjectGroupId",
                    "controlPoints.xValue", "controlPoints.yValue",
                    "controlPoints.zValue", "blindDataNodes", "uvSet",
                    "uvSet.uvSetName", "uvSet.uvSetPoints",
                    "uvSet.uvSetPoints.uvSetPointsU",
                    "uvSet.uvSetPoints.uvSetPointsV",
                    "uvSet.uvSetTweakLocation", "colorSet.colorName",
                    "colorSet.clamped", "colorSet.representation",
                    "colorSet.colorSetPoints",
                    "colorSet.colorSetPoints.colorSetPointsR",
                    "colorSet.colorSetPoints.colorSetPointsG",
                    "colorSet.colorSetPoints.colorSetPointsB",
                    "colorSet.colorSetPoints.colorSetPointsA",
                    "collisionOffsetVelocityIncrement.collisionOffsetVelocityIncrement_Position",
                    "collisionOffsetVelocityIncrement.collisionOffsetVelocityIncrement_FloatValue",
                    "collisionOffsetVelocityIncrement.collisionOffsetVelocityIncrement_Interp",
                    "collisionDepthVelocityIncrement.collisionDepthVelocityIncrement_Position",
                    "collisionDepthVelocityIncrement.collisionDepthVelocityIncrement_FloatValue",
                    "collisionDepthVelocityIncrement.collisionDepthVelocityIncrement_Interp",
                    "collisionOffsetVelocityMultiplier",
                    "collisionOffsetVelocityMultiplier.collisionOffsetVelocityMultiplier_Position",
                    "collisionOffsetVelocityMultiplier.collisionOffsetVelocityMultiplier_FloatValue",
                    "collisionOffsetVelocityMultiplier.collisionOffsetVelocityMultiplier_Interp",
                    "collisionDepthVelocityMultiplier",
                    "collisionDepthVelocityMultiplier.collisionDepthVelocityMultiplier_Position",
                    "collisionDepthVelocityMultiplier.collisionDepthVelocityMultiplier_FloatValue",
                    "collisionDepthVelocityMultiplier.collisionDepthVelocityMultiplier_Interp",
                    "outGeometryClean", "pnts.pntx", "pnts.pnty", "pnts.pntz",
                    "vrts", "vrts.vrtx", "vrts.vrty", "vrts.vrtz", "edge",
                    "edge.edg1", "edge.edg2", "edge.edgh", "uvpt.uvpx",
                    "uvpt.uvpy", "colors.colorR", "colors.colorG",
                    "colors.colorB", "colors.colorA", "normals.normalx",
                    "normals.normaly", "normals.normalz", "face",
                    "colorPerVertex", "vertexColor.vertexColorRGB",
                    "vertexColor.vertexColorR", "vertexColor.vertexColorG",
                    "vertexColor.vertexColorB", "vertexColor.vertexAlpha",
                    "vertexColor.vertexFaceColor",
                    "vertexColor.vertexFaceColor.vertexFaceColorRGB",
                    "vertexColor.vertexFaceColor.vertexFaceColorR",
                    "vertexColor.vertexFaceColor.vertexFaceColorG",
                    "vertexColor.vertexFaceColor.vertexFaceColorB",
                    "vertexColor.vertexFaceColor.vertexFaceAlpha",
                    "normalPerVertex", "vertexNormal.vertexNormalXYZ",
                    "vertexNormal.vertexNormalX", "vertexNormal.vertexNormalY",
                    "vertexNormal.vertexNormalZ",
                    "vertexNormal.vertexFaceNormal",
                    "vertexNormal.vertexFaceNormal.vertexFaceNormalXYZ",
                    "vertexNormal.vertexFaceNormal.vertexFaceNormalX",
                    "vertexNormal.vertexFaceNormal.vertexFaceNormalY",
                    "vertexNormal.vertexFaceNormal.vertexFaceNormalZ"
                ]

            if self.XformNodeType == "transform" and self.shapeNodeType == "VRayLightRectShape":
                attrsRem_xform = [
                    "message", "caching", "isHistoricallyInteresting",
                    "nodeState", "binMembership", "hyperLayout", "isCollapsed",
                    "blackBox", "borderConnections",
                    "isHierarchicalConnection", "publishedNodeInfo",
                    "publishedNodeInfo.publishedNode",
                    "publishedNodeInfo.isHierarchicalNode",
                    "publishedNodeInfo.publishedNodeType", "rmbCommand",
                    "templateName", "templatePath", "viewName", "iconName",
                    "viewMode", "templateVersion", "uiTreatment",
                    "customTreatment", "creator", "creationDate",
                    "containerType", "boundingBox", "boundingBoxMin",
                    "boundingBoxMinX", "boundingBoxMinY", "boundingBoxMinZ",
                    "boundingBoxMax", "boundingBoxMaxX", "boundingBoxMaxY",
                    "boundingBoxMaxZ", "boundingBoxSize", "boundingBoxSizeX",
                    "boundingBoxSizeY", "boundingBoxSizeZ", "center",
                    "boundingBoxCenterX", "boundingBoxCenterY",
                    "boundingBoxCenterZ", "matrix", "inverseMatrix",
                    "worldMatrix", "worldInverseMatrix", "parentMatrix",
                    "parentInverseMatrix", "visibility", "intermediateObject",
                    "template", "ghosting", "instObjGroups",
                    "instObjGroups.objectGroups",
                    "instObjGroups.objectGroups.objectGrpCompList",
                    "instObjGroups.objectGroups.objectGroupId",
                    "instObjGroups.objectGroups.objectGrpColor",
                    "objectColorRGB", "objectColorR", "objectColorG",
                    "objectColorB", "useObjectColor", "objectColor",
                    "drawOverride", "overrideDisplayType",
                    "overrideLevelOfDetail", "overrideShading",
                    "overrideTexturing", "overridePlayback", "overrideEnabled",
                    "overrideVisibility", "overrideColor", "lodVisibility",
                    "selectionChildHighlighting", "renderInfo",
                    "identification", "layerRenderable", "layerOverrideColor",
                    "renderLayerInfo", "renderLayerInfo.renderLayerId",
                    "renderLayerInfo.renderLayerRenderable",
                    "renderLayerInfo.renderLayerColor", "ghostingControl",
                    "ghostCustomSteps", "ghostPreSteps", "ghostPostSteps",
                    "ghostStepSize", "ghostFrames", "ghostColorPreA",
                    "ghostColorPre", "ghostColorPreR", "ghostColorPreG",
                    "ghostColorPreB", "ghostColorPostA", "ghostColorPost",
                    "ghostColorPostR", "ghostColorPostG", "ghostColorPostB",
                    "ghostRangeStart", "ghostRangeEnd", "ghostDriver",
                    "hiddenInOutliner", "translate", "rotate", "scale",
                    "shear", "rotatePivot", "rotatePivotTranslate",
                    "scalePivot", "scalePivotTranslate", "rotateAxis",
                    "transMinusRotatePivot", "minTransLimit", "maxTransLimit",
                    "minTransLimitEnable", "maxTransLimitEnable",
                    "minRotLimit", "maxRotLimit", "minRotLimitEnable",
                    "maxRotLimitEnable", "minScaleLimit", "maxScaleLimit",
                    "minScaleLimitEnable", "maxScaleLimitEnable",
                    "selectHandle", "rotateQuaternion", "mentalRayControls"
                ]
                #"mentalRayControls"]

                attrsRem_shape = [
                    "message", "caching", "isHistoricallyInteresting",
                    "nodeState", "binMembership", "hyperLayout", "isCollapsed",
                    "blackBox", "borderConnections",
                    "isHierarchicalConnection", "publishedNodeInfo",
                    "publishedNodeInfo.publishedNode",
                    "publishedNodeInfo.isHierarchicalNode",
                    "publishedNodeInfo.publishedNodeType", "rmbCommand",
                    "templateName", "templatePath", "viewName", "iconName",
                    "viewMode", "templateVersion", "uiTreatment",
                    "customTreatment", "creator", "creationDate",
                    "containerType", "boundingBox", "boundingBoxMin",
                    "boundingBoxMinX", "boundingBoxMinY", "boundingBoxMinZ",
                    "boundingBoxMax", "boundingBoxMaxX", "boundingBoxMaxY",
                    "boundingBoxMaxZ", "boundingBoxSize", "boundingBoxSizeX",
                    "boundingBoxSizeY", "boundingBoxSizeZ", "center",
                    "boundingBoxCenterX", "boundingBoxCenterY",
                    "boundingBoxCenterZ", "matrix", "inverseMatrix",
                    "worldMatrix", "worldInverseMatrix", "parentMatrix",
                    "parentInverseMatrix", "visibility", "intermediateObject",
                    "template", "ghosting", "instObjGroups",
                    "instObjGroups.objectGroups",
                    "instObjGroups.objectGroups.objectGrpCompList",
                    "instObjGroups.objectGroups.objectGroupId",
                    "instObjGroups.objectGroups.objectGrpColor",
                    "objectColorRGB", "objectColorR", "objectColorG",
                    "objectColorB", "useObjectColor", "objectColor",
                    "drawOverride", "overrideDisplayType",
                    "overrideLevelOfDetail", "overrideShading",
                    "overrideTexturing", "overridePlayback", "overrideEnabled",
                    "overrideVisibility", "overrideColor", "lodVisibility",
                    "selectionChildHighlighting", "renderInfo",
                    "identification", "layerRenderable", "layerOverrideColor",
                    "renderLayerInfo", "renderLayerInfo.renderLayerId",
                    "renderLayerInfo.renderLayerRenderable",
                    "renderLayerInfo.renderLayerColor", "ghostingControl",
                    "ghostCustomSteps", "ghostPreSteps", "ghostPostSteps",
                    "ghostStepSize", "ghostFrames", "ghostColorPreA",
                    "ghostColorPre", "ghostColorPreR", "ghostColorPreG",
                    "ghostColorPreB", "ghostColorPostA", "ghostColorPost",
                    "ghostColorPostR", "ghostColorPostG", "ghostColorPostB",
                    "ghostRangeStart", "ghostRangeEnd", "ghostDriver",
                    "hiddenInOutliner", "referenceObject",
                    "compInstObjGroups.compObjectGroups.compObjectGrpCompList",
                    "compInstObjGroups.compObjectGroups.compObjectGroupId",
                    "localPosition", "worldPosition", "localScale",
                    "targetPos", "lightData", "lightDirection",
                    "lightIntensity", "compInstObjGroups"
                ]
                #,"mentalRayControls","miRenderPassList"]

            if self.XformNodeType == "transform" and self.shapeNodeType == "camera":
                attrsRem_xform = [
                    "message", "caching", "isHistoricallyInteresting",
                    "nodeState", "binMembership", "hyperLayout", "isCollapsed",
                    "blackBox", "borderConnections",
                    "isHierarchicalConnection", "publishedNodeInfo",
                    "publishedNodeInfo.publishedNode",
                    "publishedNodeInfo.isHierarchicalNode",
                    "publishedNodeInfo.publishedNodeType", "rmbCommand",
                    "templateName", "templatePath", "viewName", "iconName",
                    "viewMode", "templateVersion", "uiTreatment",
                    "customTreatment", "creator", "creationDate",
                    "containerType", "boundingBox", "boundingBoxMin",
                    "boundingBoxMinX", "boundingBoxMinY", "boundingBoxMinZ",
                    "boundingBoxMax", "boundingBoxMaxX", "boundingBoxMaxY",
                    "boundingBoxMaxZ", "boundingBoxSize", "boundingBoxSizeX",
                    "boundingBoxSizeY", "boundingBoxSizeZ", "center",
                    "boundingBoxCenterX", "boundingBoxCenterY",
                    "boundingBoxCenterZ", "matrix", "inverseMatrix",
                    "worldMatrix", "worldInverseMatrix", "parentMatrix",
                    "parentInverseMatrix", "visibility", "intermediateObject",
                    "template", "ghosting", "instObjGroups",
                    "instObjGroups.objectGroups",
                    "instObjGroups.objectGroups.objectGrpCompList",
                    "instObjGroups.objectGroups.objectGroupId",
                    "instObjGroups.objectGroups.objectGrpColor",
                    "objectColorRGB", "objectColorR", "objectColorG",
                    "objectColorB", "useObjectColor", "objectColor",
                    "drawOverride", "overrideDisplayType",
                    "overrideLevelOfDetail", "overrideShading",
                    "overrideTexturing", "overridePlayback", "overrideEnabled",
                    "overrideVisibility", "overrideColor", "lodVisibility",
                    "selectionChildHighlighting", "renderInfo",
                    "identification", "layerRenderable", "layerOverrideColor",
                    "renderLayerInfo", "renderLayerInfo.renderLayerId",
                    "renderLayerInfo.renderLayerRenderable",
                    "renderLayerInfo.renderLayerColor", "ghostingControl",
                    "ghostCustomSteps", "ghostPreSteps", "ghostPostSteps",
                    "ghostStepSize", "ghostFrames", "ghostColorPreA",
                    "ghostColorPre", "ghostColorPreR", "ghostColorPreG",
                    "ghostColorPreB", "ghostColorPostA", "ghostColorPost",
                    "ghostColorPostR", "ghostColorPostG", "ghostColorPostB",
                    "ghostRangeStart", "ghostRangeEnd", "ghostDriver",
                    "hiddenInOutliner", "translate", "rotate", "scale",
                    "shear", "rotatePivot", "rotatePivotTranslate",
                    "scalePivot", "scalePivotTranslate", "rotateAxis",
                    "transMinusRotatePivot", "minTransLimit", "maxTransLimit",
                    "minTransLimitEnable", "maxTransLimitEnable",
                    "minRotLimit", "maxRotLimit", "minRotLimitEnable",
                    "maxRotLimitEnable", "minScaleLimit", "maxScaleLimit",
                    "minScaleLimitEnable", "maxScaleLimitEnable",
                    "selectHandle", "rotateQuaternion", "mentalRayControls"
                ]
                #"mentalRayControls"]

                attrsRem_shape = [
                    "message", "caching", "isHistoricallyInteresting",
                    "nodeState", "binMembership", "hyperLayout", "isCollapsed",
                    "blackBox", "borderConnections",
                    "isHierarchicalConnection", "publishedNodeInfo",
                    "publishedNodeInfo.publishedNode",
                    "publishedNodeInfo.isHierarchicalNode",
                    "publishedNodeInfo.publishedNodeType", "rmbCommand",
                    "templateName", "templatePath", "viewName", "iconName",
                    "viewMode", "templateVersion", "uiTreatment",
                    "customTreatment", "creator", "creationDate",
                    "containerType", "boundingBox", "boundingBoxMin",
                    "boundingBoxMinX", "boundingBoxMinY", "boundingBoxMinZ",
                    "boundingBoxMax", "boundingBoxMaxX", "boundingBoxMaxY",
                    "boundingBoxMaxZ", "boundingBoxSize", "boundingBoxSizeX",
                    "boundingBoxSizeY", "boundingBoxSizeZ", "center",
                    "boundingBoxCenterX", "boundingBoxCenterY",
                    "boundingBoxCenterZ", "matrix", "inverseMatrix",
                    "worldMatrix", "worldInverseMatrix", "parentMatrix",
                    "parentInverseMatrix", "visibility", "intermediateObject",
                    "template", "ghosting", "instObjGroups",
                    "instObjGroups.objectGroups",
                    "instObjGroups.objectGroups.objectGrpCompList",
                    "instObjGroups.objectGroups.objectGroupId",
                    "instObjGroups.objectGroups.objectGrpColor",
                    "objectColorRGB", "objectColorR", "objectColorG",
                    "objectColorB", "useObjectColor", "objectColor",
                    "drawOverride", "overrideDisplayType",
                    "overrideLevelOfDetail", "overrideShading",
                    "overrideTexturing", "overridePlayback", "overrideEnabled",
                    "overrideVisibility", "overrideColor", "lodVisibility",
                    "selectionChildHighlighting", "renderInfo",
                    "identification", "layerRenderable", "layerOverrideColor",
                    "renderLayerInfo", "renderLayerInfo.renderLayerId",
                    "renderLayerInfo.renderLayerRenderable",
                    "renderLayerInfo.renderLayerColor", "ghostingControl",
                    "ghostCustomSteps", "ghostPreSteps", "ghostPostSteps",
                    "ghostStepSize", "ghostFrames", "ghostColorPreA",
                    "ghostColorPre", "ghostColorPreR", "ghostColorPreG",
                    "ghostColorPreB", "ghostColorPostA", "ghostColorPost",
                    "ghostColorPostR", "ghostColorPostG", "ghostColorPostB",
                    "ghostRangeStart", "ghostRangeEnd", "ghostDriver",
                    "hiddenInOutliner", "stereoHorizontalImageTranslate",
                    "stereoHorizontalImageTranslateEnabled", "postProjection",
                    "filmRollControl", "imagePlane", "bookmarks"
                ]
                #"mentalRayControls","miRenderPassList"]

            xformNode1Attrs = cmds.listAttr(xformNode1)
            #print "xformNode1Attrs = ",xformNode1Attrs
            for rm in attrsRem_xform:
                #print "xformNode1Attrs = ",xformNode1Attrs
                #print "rm1 = ",rm
                xformNode1Attrs.remove(rm)
            shapeNode1Attrs = cmds.listAttr(shapeNode1)
            #print "shapeNode1Attrs = ",shapeNode1Attrs
            for rm in attrsRem_shape:
                #print "rm2 = ",rm
                shapeNode1Attrs.remove(rm)
            xformNode2Attrs = cmds.listAttr(xformNode2)
            #print "xformNode2Attrs = ",xformNode2Attrs
            for rm in attrsRem_xform:
                #print "xformNode2Attrs = ",xformNode2Attrs
                #print "rm3 = ",rm
                xformNode2Attrs.remove(rm)
            shapeNode2Attrs = cmds.listAttr(shapeNode2)
            #print "shapeNode2Attrs = ",shapeNode2Attrs
            for rm in attrsRem_shape:
                #print "rm4 = ",rm
                shapeNode2Attrs.remove(rm)

            for xnA1 in xformNode1Attrs:
                for xnA2 in xformNode2Attrs:
                    if xnA1 == xnA2:
                        #print xnA2
                        val1 = cmds.getAttr(xformNode1 + "." + xnA1)
                        typ = type(val1)
                        typ = str(typ)
                        typ = typ.replace("<type '", "")
                        typ = typ.replace("'>", "")
                        if typ == "float" or typ == "int":
                            lckState = cmds.lockNode((xformNode2 + "." + xnA2),
                                                     lock=True,
                                                     query=True)
                            lckState = lckState[0]
                            if lckState == 0:
                                print "transfering attribute " + (
                                    xformNode1 + "." + xnA2
                                ) + " value of " + str(val1) + " to " + (
                                    xformNode2 + "." + xnA2)
                                cmds.setAttr((xformNode2 + "." + xnA2), val1)
                        if typ == "bool":
                            lckState = cmds.lockNode((xformNode2 + "." + xnA2),
                                                     lock=True,
                                                     query=True)
                            lckState = lckState[0]
                            if lckState == 0:
                                print "transfering attribute " + (
                                    xformNode1 + "." + xnA2
                                ) + " value of " + str(val1) + " to " + (
                                    xformNode2 + "." + xnA2)
                                cmds.setAttr((xformNode2 + "." + xnA2), val1)
                        if typ == "list":
                            val1 = val1[0]
                            strVal1 = str(val1)
                            strVal1 = strVal1.replace("(", "")
                            strVal1 = strVal1.replace(")", "")
                            spVal1 = strVal1.split(",")
                            sizVal = len(spVal1)
                            if sizVal == 2:
                                strSet = (xformNode2 + "." + xnA2)
                                lckState = cmds.lockNode(strSet,
                                                         lock=True,
                                                         query=True)
                                lckState = lckState[0]
                                if lckState == 0:
                                    print "transfering attribute " + (
                                        xformNode1 + "." + xnA2
                                    ) + " value of " + str(val1) + " to " + (
                                        xformNode2 + "." + xnA2)
                                    cmds.setAttr(strSet, val1[0], val1[1])
                            if sizVal == 3:
                                strSet = (xformNode2 + "." + xnA2)
                                lckState = cmds.lockNode(strSet,
                                                         lock=True,
                                                         query=True)
                                lckState = lckState[0]
                                if lckState == 0:
                                    print "transfering attribute " + (
                                        xformNode1 + "." + xnA2
                                    ) + " value of " + str(val1) + " to " + (
                                        xformNode2 + "." + xnA2)
                                    cmds.setAttr(strSet, val1[0], val1[1],
                                                 val1[2])
                            if sizVal == 4:
                                strSet = (xformNode2 + "." + xnA2)
                                lckState = cmds.lockNode(strSet,
                                                         lock=True,
                                                         query=True)
                                lckState = lckState[0]
                                if lckState == 0:
                                    print "transfering attribute " + (
                                        xformNode1 + "." + xnA2
                                    ) + " value of " + str(val1) + " to " + (
                                        xformNode2 + "." + xnA2)
                                    cmds.setAttr(strSet, val1[0], val1[1],
                                                 val1[2])

            for xnA1 in xformNode1Attrs:
                for xnA2 in xformNode2Attrs:
                    if xnA1 == xnA2:
                        conTypes = []
                        cons = cmds.listConnections(xformNode1 + "." +
                                                    xnA1) or []
                        for con in cons:
                            conType = cmds.nodeType(cons)
                            if "ramp" == conType:
                                print "connecting " + con + " to " + (
                                    xformNode2 + "." + xnA2)
                                cmds.connectAttr((con + ".outColor"),
                                                 (xformNode2 + "." + xnA2),
                                                 force=True)

            for xnA1 in shapeNode1Attrs:
                for xnA2 in shapeNode2Attrs:
                    if xnA1 == xnA2:
                        #print xnA2
                        val1 = cmds.getAttr(shapeNode1 + "." + xnA1)
                        typ = type(val1)
                        typ = str(typ)
                        typ = typ.replace("<type '", "")
                        typ = typ.replace("'>", "")
                        if typ == "float" or typ == "int":
                            lckState = cmds.lockNode((shapeNode2 + "." + xnA2),
                                                     lock=True,
                                                     query=True)
                            lckState = lckState[0]
                            if lckState == 0:
                                print "transfering attribute " + (
                                    shapeNode1 + "." + xnA2
                                ) + " value of " + str(val1) + " to " + (
                                    shapeNode2 + "." + xnA2)
                                cmds.setAttr((shapeNode2 + "." + xnA2), val1)
                        if typ == "bool":
                            lckState = cmds.lockNode((shapeNode2 + "." + xnA2),
                                                     lock=True,
                                                     query=True)
                            lckState = lckState[0]
                            if lckState == 0:
                                print "transfering attribute " + (
                                    shapeNode1 + "." + xnA2
                                ) + " value of " + str(val1) + " to " + (
                                    shapeNode2 + "." + xnA2)
                                cmds.setAttr((shapeNode2 + "." + xnA2), val1)
                        if typ == "list":
                            val1 = val1[0]
                            strVal1 = str(val1)
                            strVal1 = strVal1.replace("(", "")
                            strVal1 = strVal1.replace(")", "")
                            spVal1 = strVal1.split(",")
                            sizVal = len(spVal1)
                            if sizVal == 2:
                                strSet = (shapeNode2 + "." + xnA2)
                                lckState = cmds.lockNode(strSet,
                                                         lock=True,
                                                         query=True)
                                lckState = lckState[0]
                                if lckState == 0:
                                    print "transfering attribute " + (
                                        shapeNode1 + "." + xnA2
                                    ) + " value of " + str(val1) + " to " + (
                                        shapeNode2 + "." + xnA2)
                                    cmds.setAttr(strSet, val1[0], val1[1])
                            if sizVal == 3:
                                strSet = (shapeNode2 + "." + xnA2)
                                lckState = cmds.lockNode(strSet,
                                                         lock=True,
                                                         query=True)
                                lckState = lckState[0]
                                if lckState == 0:
                                    print "transfering attribute " + (
                                        shapeNode1 + "." + xnA2
                                    ) + " value of " + str(val1) + " to " + (
                                        shapeNode2 + "." + xnA2)
                                    cmds.setAttr(strSet, val1[0], val1[1],
                                                 val1[2])
                            if sizVal == 4:
                                strSet = (shapeNode2 + "." + xnA2)
                                lckState = cmds.lockNode(strSet,
                                                         lock=True,
                                                         query=True)
                                lckState = lckState[0]
                                if lckState == 0:
                                    print "transfering attribute " + (
                                        shapeNode1 + "." + xnA2
                                    ) + " value of " + str(val1) + " to " + (
                                        shapeNode2 + "." + xnA2)
                                    cmds.setAttr(strSet, val1[0], val1[1],
                                                 val1[2])
            for xnA1 in shapeNode1Attrs:
                for xnA2 in shapeNode2Attrs:
                    if xnA1 == xnA2:
                        conTypes = []
                        cons = cmds.listConnections(shapeNode1 + "." +
                                                    xnA1) or []
                        for con in cons:
                            conType = cmds.nodeType(cons)
                            if "ramp" == conType:
                                print "connecting " + con + " to " + (
                                    shapeNode2 + "." + xnA2)
                                cmds.connectAttr((con + ".outColor"),
                                                 (shapeNode2 + "." + xnA2),
                                                 force=True)

        if self.XformNodeType == "transform" and self.shapeNodeType == "VRayLightRectShape":
            obs = cmds.ls()
            for ob in obs:
                #print "unlinking " + shapeNode2 + " from " + ob
                cmds.lightlink(b=True, light=shapeNode2, object=ob)
            links = cmds.lightlink(query=True, light=shapeNode1)
            for link in links:
                if link != "initialShadingGroup":
                    print "linking " + shapeNode2 + " to " + link
                    cmds.lightlink(make=True, light=shapeNode2, object=link)

        if self.Node1Type == "VRayMtl":
            if self.Node1Type == "VRayMtl":
                xformNode1 = self.nodeOne
                xformNode2 = self.nodeTwo
                attrsRem_xform = [
                    "message", "anisotropyUVWGen", "attributeAliasList"
                ]
                #"mentalRayControls"]

            xformNode1Attrs = cmds.listAttr(xformNode1)
            #print "xformNode1Attrs = ",xformNode1Attrs
            for rm in attrsRem_xform:
                #print "xformNode1Attrs = ",xformNode1Attrs
                #print "rm1 = ",rm
                xformNode1Attrs.remove(rm)
            xformNode2Attrs = cmds.listAttr(xformNode2)
            #print "xformNode2Attrs = ",xformNode2Attrs
            for rm in attrsRem_xform:
                #print "xformNode2Attrs = ",xformNode2Attrs
                #print "rm3 = ",rm
                xformNode2Attrs.remove(rm)
            for xnA1 in xformNode1Attrs:
                for xnA2 in xformNode2Attrs:
                    if xnA1 == xnA2:
                        #print xnA2
                        val1 = cmds.getAttr(xformNode1 + "." + xnA1)
                        typ = type(val1)
                        typ = str(typ)
                        typ = typ.replace("<type '", "")
                        typ = typ.replace("'>", "")
                        if typ == "float" or typ == "int":
                            lckState = cmds.lockNode((xformNode2 + "." + xnA2),
                                                     lock=True,
                                                     query=True)
                            lckState = lckState[0]
                            if lckState == 0:
                                print "transfering attribute " + (
                                    xformNode1 + "." + xnA2
                                ) + " value of " + str(val1) + " to " + (
                                    xformNode2 + "." + xnA2)
                                cmds.setAttr((xformNode2 + "." + xnA2), val1)
                        if typ == "bool":
                            lckState = cmds.lockNode((xformNode2 + "." + xnA2),
                                                     lock=True,
                                                     query=True)
                            lckState = lckState[0]
                            if lckState == 0:
                                print "transfering attribute " + (
                                    xformNode1 + "." + xnA2
                                ) + " value of " + str(val1) + " to " + (
                                    xformNode2 + "." + xnA2)
                                cmds.setAttr((xformNode2 + "." + xnA2), val1)
                        if typ == "list":
                            val1 = val1[0]
                            strVal1 = str(val1)
                            strVal1 = strVal1.replace("(", "")
                            strVal1 = strVal1.replace(")", "")
                            spVal1 = strVal1.split(",")
                            sizVal = len(spVal1)
                            if sizVal == 2:
                                strSet = (xformNode2 + "." + xnA2)
                                lckState = cmds.lockNode(strSet,
                                                         lock=True,
                                                         query=True)
                                lckState = lckState[0]
                                if lckState == 0:
                                    print "transfering attribute " + (
                                        xformNode1 + "." + xnA2
                                    ) + " value of " + str(val1) + " to " + (
                                        xformNode2 + "." + xnA2)
                                    cmds.setAttr(strSet, val1[0], val1[1])
                            if sizVal == 3:
                                strSet = (xformNode2 + "." + xnA2)
                                lckState = cmds.lockNode(strSet,
                                                         lock=True,
                                                         query=True)
                                lckState = lckState[0]
                                if lckState == 0:
                                    print "transfering attribute " + (
                                        xformNode1 + "." + xnA2
                                    ) + " value of " + str(val1) + " to " + (
                                        xformNode2 + "." + xnA2)
                                    cmds.setAttr(strSet, val1[0], val1[1],
                                                 val1[2])
                            if sizVal == 4:
                                strSet = (xformNode2 + "." + xnA2)
                                lckState = cmds.lockNode(strSet,
                                                         lock=True,
                                                         query=True)
                                lckState = lckState[0]
                                if lckState == 0:
                                    print "transfering attribute " + (
                                        xformNode1 + "." + xnA2
                                    ) + " value of " + str(val1) + " to " + (
                                        xformNode2 + "." + xnA2)
                                    cmds.setAttr(strSet, val1[0], val1[1],
                                                 val1[2])
            for xnA1 in xformNode1Attrs:
                for xnA2 in xformNode2Attrs:
                    if xnA1 == xnA2:
                        conTypes = []
                        cons = cmds.listConnections(xformNode1 + "." +
                                                    xnA1) or []
                        for con in cons:
                            conType = cmds.nodeType(cons)
                            if "ramp" == conType:
                                print "connecting " + con + " to " + (
                                    xformNode2 + "." + xnA2)
                                cmds.connectAttr((con + ".outColor"),
                                                 (xformNode2 + "." + xnA2),
                                                 force=True)
예제 #25
0
import maya.cmds as cmds
import json
import os
​
def reverse_light_linking(meshes, lights):
    selection = cmds.ls(dag=1,o=1,s=1,sl=1)
    lights    = cmds.ls(selection, type=["light"] + cmds.listNodeTypes("light"))
    meshes    = list(set(selection) - set(lights))
​
    if selection == [] or not lights or not meshes: return "error:Please select some Object to link"
​
    if lights == True: 
        scene_lights   = cmds.ls(type=["light"] + cmds.listNodeTypes("light"))
        exclude_lights = list(set(scene_lights) - set(lights))
        cmds.lightlink(light=exclude_lights, object=meshes, b=True)
​
    elif meshes == True:  
        exclude_meshes = list(set(cmds.ls(dag=1,o=1,s=1)) - set(meshes))
        cmds.lightlink(light=lights, object=exclude_meshes, b=True)
​
​
def export_lightlinks():
    
    raw_name, extension = os.path.splitext(cmds.file(q=True, sn=True, shn=True))
    if raw_name == "":
        filename = "untitled"
    else:
        filename = raw_name
    filepath = "{0}{1}.llink".format(cmds.workspace(q=True, rootDirectory=True),filename)
        
    lights = cmds.ls(type=["light"] + cmds.listNodeTypes("light"))