Example #1
0
def exportHData(asset):
    # get publish maya file
    pubMayaFile = asset.publishFile()

    # replace to yml
    pubHDataFile = pubMayaFile.replace(".ma", ".yml")
    hDir = asset.rigDataPath("hdata")
    hFileName = "%s/%s" % (hDir, os.path.basename(pubHDataFile))

    if not os.path.exists(hDir):
        os.makedirs(hDir)

    if not os.path.exists(os.path.dirname(pubHDataFile)):
        os.makedirs(os.path.dirname(pubHDataFile))

    result = pt.exportHierarchyData(setting.exportGrp, pubHDataFile)

    if result:
        # copy to work area
        fileUtils.copy(pubHDataFile, hFileName)

    status = False

    if result:
        status = True

    return {"Export H-Data": {"status": status, "message": "", "hero": result}}
Example #2
0
def exportAnim(namespace, exportFile) : 
	# ctrls
	set1 = mc.ls('%s:*_ctrl' % namespace)
	set2 = mc.ls('%s:*:*_ctrl' % namespace)
	set3 = mc.ls('%s:*:*:*_ctrl' % namespace)
	set4 = mc.ls('%s:*_Ctrl' % namespace)
	set5 = mc.ls('%s:*:*_Ctrl' % namespace)
	set6 = mc.ls('%s:*:*:*_Ctrl' % namespace)

	ctrls = set1+set2+set3+set4+set5+set6

	animFile = '%s/%s.anim' % (exportFile, namespace)

	# manage dirs 
	if not os.path.exists(exportFile) : 
		os.makedirs(exportFile)

	# export command 
	mc.select(ctrls)

	tempFile = '%s/temp.anim' % mc.internalVar(utd = True)
	mm.eval('file -force -options "precision=8;intValue=17;nodeNames=1;verboseUnits=0;whichRange=1;range=1:24;options=keys;hierarchy=none;controlPoints=0;shapes=0;helpPictures=0;useChannelBox=0;copyKeyCmd=-animation objects -option keys -hierarchy none -controlPoints 0 -shape 0 " -typ "animExport" -pr -es "%s";' % tempFile)

	fileUtils.copy(tempFile, animFile)
	os.remove(tempFile)

	# export selection controllers 
	exportFilePath = '%s/%s.txt' % (exportFile, namespace)
	fileUtils.writeFile(exportFilePath, str(ctrls))

	mc.select(cl = True)

	return True 
Example #3
0
def exportAnim(namespace, exportFile) : 
	# ctrls
	set1 = mc.ls('%s:*_ctrl' % namespace)
	set2 = mc.ls('%s:*:*_ctrl' % namespace)
	set3 = mc.ls('%s:*:*:*_ctrl' % namespace)
	set4 = mc.ls('%s:*_Ctrl' % namespace)
	set5 = mc.ls('%s:*:*_Ctrl' % namespace)
	set6 = mc.ls('%s:*:*:*_Ctrl' % namespace)

	ctrls = set1+set2+set3+set4+set5+set6

	animFile = '%s/%s.anim' % (exportFile, namespace)

	# manage dirs 
	if not os.path.exists(exportFile) : 
		os.makedirs(exportFile)

	# export command 
	mc.select(ctrls)

	tempFile = '%s/temp.anim' % mc.internalVar(utd = True)
	mm.eval('file -force -options "precision=8;intValue=17;nodeNames=1;verboseUnits=0;whichRange=1;range=1:24;options=keys;hierarchy=none;controlPoints=0;shapes=0;helpPictures=0;useChannelBox=0;copyKeyCmd=-animation objects -option keys -hierarchy none -controlPoints 0 -shape 0 " -typ "animExport" -pr -es "%s";' % tempFile)

	fileUtils.copy(tempFile, animFile)
	os.remove(tempFile)

	# export selection controllers 
	exportFilePath = '%s/%s.txt' % (exportFile, namespace)
	fileUtils.writeFile(exportFilePath, str(ctrls))

	mc.select(cl = True)

	return True 
Example #4
0
def saveStill(mediaType='still', ext=False):
    asset = entityInfo.info()
    # save to surface
    mediaDir = asset.surfaceOutput(mediaType)
    currentFile = asset.fileName(ext=False)

    files = fileUtils.listFile(mediaDir)
    fileName = '%s_%02d' % (currentFile, 1)

    if files:
        fileCount = 0

        for each in files:
            if currentFile in each:
                fileCount += 1

        fileName = '%s_%02d' % (currentFile, fileCount + 1)

    # save to surface
    result = saveVrayRender(mediaDir, fileName, img='jpg')
    print 'Saved to %s' % result

    if result:
        src = '%s.jpg' % result

        if os.path.exists(src):
            # save to hero
            heroDir = asset.mediaHeroName(mediaType=mediaType, returnPath=True)
            dst = '%s.jpg' % heroDir
            result2 = fileUtils.copy(src, dst)

            print 'Saved to %s' % result2

        return src
	def manageMediaFile(self) : 
		# target file
		targetFile = self.asset.publishImageFile()
		dir = os.path.dirname(targetFile)

		# input files 
		current = str(self.ui.thumbnail_lineEdit.text())
		currentMedia = str(self.ui.media_lineEdit.text())

		if os.path.exists(current) : 
			if not current == targetFile : 
				fileUtils.copy(current, targetFile)
				logger.debug('Copy thumbnail %s -> %s' % (current, targetFile))

			else : 
				logger.debug('Thumbnail not copy')

			# copy to images/icon 
			if self.asset.department() in setting.heroIconDept : 
				heroIcon = self.asset.getPath('icon')
				fileUtils.copy(current, heroIcon)
				logger.debug('Copy hero thumbnail')

		if os.path.exists(currentMedia) : 
			ext = currentMedia.split('.')[-1]
			targetMedia = '%s.%s' % (targetFile.split('.')[0], ext)

			if not targetMedia == targetFile : 
				fileUtils.copy(currentMedia, targetMedia)
				logger.debug('Copy media %s -> %s' % (currentMedia, targetMedia))

			else : 
				logger.debug('Media not copy')

		return True 
Example #6
0
def exportShotAsmLocator(bake=False) : 
    """ export multiple sets from shot """
    currentObjs = mc.ls(assemblies=True)

    try : 
        # roots = createAsmLocator(bake)
        asmLocator = asm.AsmLocator()
        roots = asmLocator.create()
        asmRoots = asm.findAssemblyRoot()
        rootVersions = findAsmVersion(asmRoots)
        shot = entityInfo.info()
        exportFiles = []
        heroLocs = []

        if roots : 
            for i, root in enumerate(roots) : 
                refPath = mc.getAttr('%s.reference' % root)
                asset = entityInfo.info(refPath)
                assetName = asset.name()
                setLocData(root, locType='shotTransform', version=rootVersions[i])

                path = shot.animOutput('assemblies', True)
                hero = shot.animOutput('assemblies', True, False)

                path = path.replace('$', assetName)
                hero = hero.replace('$', assetName)

                logger.info('--------- Exporting to Alembic --------------')
                logger.info('%s/%s' % (i, len(roots)))
                currentTime = mc.currentTime(q = True)
                start = currentTime
                end = currentTime + 1
                versionLoc = abcUtils.exportABC(['|'+root], path, start, end)
                print 'Export %s' % versionLoc
                heroLoc = fileUtils.copy(path, hero)
                print 'Copy to hero %s' % heroLoc
                
                mc.delete(['|'+root])

                heroLocs.append(heroLoc)
                
            print 'Total %s set(s)' % len(roots)
            return heroLocs

    except Exception as e : 
        newObjs = mc.ls(assemblies=True)
        addObjs = list(set(newObjs) - set(currentObjs))
        logger.warning('Create locator failed. Remove left over objects %s' % addObjs)
        # mc.delete(addObjs)

        logger.error(e)
        traceback.print_exc()
Example #7
0
def publishWork(ar=True) : 
    """ publish dress work """
    logger.info('Publishing work ...')
    saveFile = mc.file(save=True, type='mayaAscii')
    logger.debug('file saved %s' % saveFile)
    asset = entityInfo.info()
    publishDir = asset.publishDir()
    publishFile = '%s/%s' % (publishDir, os.path.basename(saveFile))

    logger.debug('copying file from %s to %s' % (saveFile, publishFile))
    result = fileUtils.copy(saveFile, publishFile)
    logger.debug('publish complete')

    if ar : 
        logger.debug('prepare to publihs AR from %s' % result)
        publishAR(result)
Example #8
0
def exportABC(asset):
    mc.loadPlugin("C:/Program Files/Autodesk/Maya2015/bin/plug-ins/AbcImport.mll", qt=True)
    from tool.ptAlembic import abcUtils

    reload(abcUtils)

    ctrl = setting.superRootCtrl
    geoGrp = setting.exportGrp

    # get publish maya file
    pubMayaFile = asset.publishFile()

    # replace to yml
    abcFile = pubMayaFile.replace(".ma", ".abc")
    abcDir = asset.rigDataPath("abc")
    abcFileName = "%s/%s" % (abcDir, os.path.basename(abcFile))

    if not os.path.exists(abcDir):
        os.makedirs(abcDir)

    if not os.path.exists(os.path.dirname(abcFile)):
        os.makedirs(os.path.dirname(abcFile))

    if mc.objExists(ctrl):
        start = mc.playbackOptions(q=True, min=True)
        end = mc.playbackOptions(q=True, max=True)

        # set animation
        setTurnAnimation(ctrl)

        # export abc
        result = abcUtils.exportABC(geoGrp, abcFile)

        if os.path.exists(abcFile):
            # copy to work area
            copyResult = fileUtils.copy(abcFile, abcFileName)

            # remove key
        removeKey(ctrl, start, end)
        status = False

        if os.path.exists(abcFile):
            status = True

        return {"Export abc": {"status": status, "message": result, "hero": result}}
Example #9
0
    def doCopy(self, autoCopy = False) : 
        dst = str(self.ui.dst_lineEdit.text()).replace('\\', '/')
        counts = self.getSelectedRow(autoCopy)
        data = []

        if dst : 
            for i in xrange(counts[0], counts[1]) : 
                item = self.ui.asset_tableWidget.item(i, self.sourcePathCol)
                
                if item : 
                    srcPath = str(item.text())
                    drive = os.path.splitdrive(srcPath)[0]
                    dstPath = srcPath.replace(drive, dst)

                    statusItem = self.ui.asset_tableWidget.item(i, self.statusCol)
                    dstItem = self.ui.asset_tableWidget.item(i, self.copyDstCol)

                    if os.path.exists(dstPath) : 
                        # statusItem.setText('OK')
                        self.setItemIcon(statusItem, i, self.statusCol, self.okIcon, 'OK')

                    else : 
                        print 'Copying %s ...' % dstPath
                        self.setItemIcon(statusItem, i, self.statusCol, self.ipIcon, 'Copying ...')
                        
                        try : 
                            result = fileUtils.copy(srcPath, dstPath)

                            if os.path.exists(dstPath) : 
                                # statusItem.setText('OK')
                                self.setItemIcon(statusItem, i, self.statusCol, self.okIcon, 'OK')
                                dstItem.setText(dstPath)

                                QtGui.QApplication.processEvents()

                        except Exception as e : 
                            self.setItemIcon(statusItem, i, self.statusCol, self.redIcon, 'Error')
                            dstItem.setText(dstPath)

                            QtGui.QApplication.processEvents()
Example #10
0
def publishAR(source) : 
    """ publish AR from dress work """
    logger.info('Publishing AR file ...')

    if os.path.exists(source) : 
        asset = entityInfo.info()
        arFile = '%s/%s' % (asset.getPath('ref'), asset.getRefNaming('ar'))


        if os.path.exists(arFile) : 
            logger.debug('File exists. Backing up %s' % arFile)
            backupResult = pipelineTools.backupRef(arFile)
            logger.debug('Backup complete %s' % backupResult)

        logger.debug('Copying %s to %s' % (source, arFile))
        result = fileUtils.copy(source, arFile)
        logger.info('Publish complete')

        return result

    else : 
        logger.warning('%s not exists. Publihsing stop.' % source)
Example #11
0
	def publishFile(self) : 
		logger.debug('--- publishing ---')

		# publish file 
		publishFile = self.svPublishFile
		workFile = self.asset.publishFile(showUser = True)
		workDir = self.asset.workDir()
		user = hook.getUser()
		self.setStatus('--- File Publish ---', True, [40, 40, 40], 0)

		if publishFile and workDir : 
			saveFile = '%s/%s' % (workDir, os.path.basename(workFile))
			# saveFile = hook.addUser(saveFile, user)

			# save file 
			logger.debug('Saving file -> %s' % saveFile)
			saveResult = hook.save(saveFile, rename = False)
			logger.info('Save file done %s' % saveResult)
			self.setStatus('Save', saveResult)

			# get increment version
			thisFile = entityInfo.info()
			incrementFile = thisFile.nextVersion()

			# manage thumbnail / media
			self.manageMediaFile()

			# extra command 
			batch = not self.ui.noBatch_checkBox.isChecked()
			refPath = self.asset.getPath('ref')
			logger.debug('Extra export -> %s' % refPath)
			extraResults = extra.publish(self.asset, batch, mainUI=self)

			if extraResults : 
				for each in extraResults : 
					title = each
					status = extraResults[each]['status']
					message = extraResults[each]['message']
					self.setStatus('%s' % title, status)
					logger.info('%s %s' % (title, message))

			# copy publish 
			logger.debug('Publish file from %s -> %s' % (saveResult, publishFile))
			copyResult = fileUtils.copy(saveResult, publishFile)
			logger.info('Publish file to %s' % publishFile)
			self.setStatus('Published', copyResult)

			if saveResult : 
				# set status 
				logger.debug('Increment file -> %s' % incrementFile)

				# increment file
				# check increment override with root file 
				fileToIncrement = str(self.ui.incrementFile_lineEdit.text())
				incrementOverride = False 
				
				if os.path.exists(fileToIncrement) and self.ui.incrementRoolFile_checkBox.isChecked() : 
					incrementOverride = True

				if batch : 
					if not incrementOverride : 
						incrementResult = hook.save(incrementFile)

					# override increment 
					else : 
						increment = entityInfo.info(fileToIncrement)
						incrementFile = increment.nextVersion()
						incrementResult = fileUtils.copy(fileToIncrement, incrementFile)

				else : 
					incrementResult = fileUtils.copy(saveResult, incrementFile)

				if incrementResult : 
					self.setStatus('Increment File', incrementResult)
					logger.info('Increment file to %s' % incrementFile)

		return True
Example #12
0
def convertTextureCmd(asset):
    print 'Convert texture'
    assetPath = asset.texturePath()
    allFiles = getFileNodes(assetPath)

    channel = {'0': '', '1':'-outchannelmap all','3':'-outrgb','4':''}
    type = {'8192':'8K','4096':'4K','2048':'2K','1024':'1K','512':'5H','256':'2H'}
    stepScale = {'8192':6,'4096':5,'2048':4,'1024':3,'512':2,'256':1}

    for file in allFiles:
        filePath = mc.getAttr('%s.fileTextureName' % file)
        print filePath
        if os.path.exists(filePath.replace('\\','/')):
            imageName = os.path.basename(filePath).split('.')[0]

            # vray tile exr
            output = os.path.join(assetPath,('\\').join([asset.taskLOD(),'exr']))
            if not os.path.exists(output.replace('\\','/')):
                os.makedirs(output.replace('\\','/')) 

            version = mc.about(v = True)
            cmd = '"C:/Program Files/Chaos Group/V-Ray/Maya 2012 for x64/bin/img2tiledexr.exe" '

            if '2015' in version : 
                cmd = '"C:/Program Files/Chaos Group/V-Ray/Maya 2015 for x64/bin/img2tiledexr.exe" '

            if '2016' in version : 
                cmd = '"C:/Program Files/Chaos Group/V-Ray/Maya 2016 for x64/bin/img2tiledexr.exe" '

            cmd += '%s ' % filePath.replace('\\','/')
            cmd += '%s.exr -32bit -compression zips -tileSize 64x64 -linear auto' % os.path.join(output,imageName).replace('\\','/')
            subprocess.Popen(cmd,stdout=subprocess.PIPE).communicate()[0]
            #

            rvReport = subprocess.Popen('"O:/systemTool/convertor/Tweak/RV-3.12.20-32/bin/rvls.exe" -l "%s"' % filePath,stdout=subprocess.PIPE).communicate()[0]
            rvReport = rvReport.split('\r\n')
            rec = {}
            print rvReport
            name = string.rsplit(rvReport[0])
            field = string.rsplit(rvReport[1])
            for i in range(len(name)):
                rec[name[i]] = field[i]
            print rec
            orgSize = rec['h']
            orgTyp = rec['typ']
            orgChannel = rec['#ch']
            

            if imageName[-1] == 'K' or imageName[-1] == 'H':
                imageName = imageName[0:-3]
            imageTyp = os.path.basename(filePath).split('.')[-1]
            scale = 1.00
            newSize = orgSize
            if not orgSize in stepScale.keys():
                newSize = checkSize(int(orgSize))
            for i in range(stepScale[newSize]):
                output = os.path.join(assetPath,('\\').join([asset.taskLOD(),type['%s'% int(int(newSize)*scale)]]))

                newFile = "%s/%s_%s.%s" % (output,imageName,type['%s'% int(int(newSize)*scale)],imageTyp)
                if not os.path.exists(output.replace('\\','/')):
                    print output.replace('\\','/')
                    os.makedirs(output.replace('\\','/')) 

                if not scale == 1.00 or not newSize == orgSize:
                    #print scale,orgTyp.split('i')[0],channel[orgChannel]
                    cmd = '"O:/systemTool/convertor/Tweak/RV-3.12.20-32/bin/rvio.exe" '
                    cmd += '"%s" ' % filePath
                    cmd += '-scale %s -codec "NONE" -outformat %s bit %s ' % (scale,
                                                                            orgTyp.split('i')[0],
                                                                            channel[orgChannel])
                    cmd += '-quality 1.0  -o "%s"' % newFile

                    subprocess.Popen(cmd,stdout=subprocess.PIPE)
                    print 'see here ============================='
                    print orgTyp.split('i')[0]
                    print channel[orgChannel]
                    print cmd 
                else:
                    if not os.path.exists(newFile.replace('\\','/')):
                        fileUtils.copy(filePath.replace('\\','/'),newFile)
                    mc.setAttr('%s.fileTextureName' % file,newFile.replace('/','\\'),type='string')

                scale *= 0.5
def main():
    logger.info('Running asmAssetExportCmd.py in batch mode ...')
    scenePath = sys.argv[1]
    logger.debug('Input argv[1], scenePath %s' % scenePath)
    # scenePath = 'P:/Lego_Pipeline/asset/3D/set/town/lpl_lab/setDress/dress/scenes/lpl_lab_dress_v025_TA.ma'

    logger.debug('Loading pipeline module ...')
    from tool.utils import entityInfo, fileUtils
    from tool.sceneAssembly import asm_utils as asmUtils
    from tool.setDress.utils import sd_utils
    reload(asmUtils)
    reload(sd_utils)
    reload(entityInfo)
    logger.debug('Loaded')

    asset = entityInfo.info(scenePath)

    mc.file(f=True, new=True)
    logger.debug('Start new scene')

    adName = '%s_AR' % asset.getRefNaming('ad', showExt=False)
    adNamespace = asset.getRefNaming('ad', showExt=False)
    adPath = '%s/%s' % (asset.getPath('ref'), asset.getRefNaming('ad'))
    locPath = '%s/%s' % (asset.getPath('ref'), asset.getRefNaming('loc'))
    publishDir = '%s/%s' % (asset.getPath('setDress'), 'publish')
    fileName = asset.fileName()
    publishMaya = '%s/%s.ma' % (publishDir, fileName)
    publishLoc = '%s/%s.abc' % (publishDir, fileName)

    if not os.path.exists(publishDir):
        os.makedirs(publishDir)
        logger.debug('%s created' % publishDir)

    logger.debug('adName : %s' % adName)
    logger.debug('adPath : %s' % adPath)
    logger.debug('adNamespace : %s' % adNamespace)

    logger.debug('creating ARNode %s ...' % adName)
    arName = asmUtils.createARNode(adName)

    logger.debug('setting ad path %s %s ...' % (arName, adPath))
    asmUtils.setARDefinitionPath(arName, adPath)

    logger.debug('setting namespace %s ...' % adNamespace)
    asmUtils.setARNamespace(arName, adNamespace)

    logger.debug('setting all active representation ...')
    asmUtils.setAllActiveRep(arName)
    logger.debug('set complete')

    mc.file(rename=publishMaya)
    logger.debug('rename scene to %s' % publishMaya)

    result = mc.file(f=True, save=True, type='mayaAscii')
    logger.debug('Virtual AR scene saved %s' % result)

    logger.info('Exporting abc locator %s ...' % locPath)
    sd_utils.exportAsmLocator(locPath, bake=False, version=scenePath)
    logger.debug('Export abc locator finish')

    logger.info('Copying abc hero ...')
    fileUtils.copy(locPath, publishLoc)
    logger.debug('Copy success %s' % publishLoc)