def publishAsset(self, iAObj=None): '''Publish the asset defined by the provided *iAObj*.''' panelComInstance = panelcom.PanelComInstance.instance() if hasattr(iAObj, 'customComponentName'): componentName = iAObj.customComponentName else: componentName = 'houdiniNodes' publishedComponents = [] temporaryPath = HelpFunctions.temporaryFile(suffix='.hip') publishedComponents.append( FTComponent( componentname=componentName, path=temporaryPath ) ) if 'exportMode' in iAObj.options and ( iAObj.options['exportMode'] == 'Selection') and ( componentName == 'houdiniNodes'): ''' Publish Selected Nodes''' selectednodes = hou.selectedNodes() selectednodes[0].parent().saveChildrenToFile( selectednodes, [], temporaryPath) panelComInstance.emitPublishProgressStep() elif componentName == 'houdiniPublishScene' and ( iAObj.options['exportMode'] == 'Selection'): # Publish Main Scene in selection mode hou.copyNodesToClipboard(hou.selectedNodes()) command = "hou.pasteNodesFromClipboard(hou.node('/obj'));\ hou.hipFile.save('%s')" % (temporaryPath) cmd = '%s -c "%s"' % (os.path.join( os.getenv('HFS'), 'bin', 'hython'), command) os.system(cmd) elif componentName == 'houdiniPublishScene': # Publish Main Scene hou.hipFile.save(temporaryPath) panelComInstance.emitPublishProgressStep() return publishedComponents, 'Published ' + iAObj.assetType + ' asset'
def publishAsset(self, iAObj=None): '''Publish the asset defined by the provided *iAObj*.''' pubMessage = 'Published cameraasset asset' # Only export selection when exporting camera iAObj.options['exportMode'] = 'Selection' publishedComponents = [] totalSteps = self.getTotalSteps(steps=[ iAObj.options['cameraBake'], iAObj.options['cameraMaya'], iAObj.options['cameraAlembic'], iAObj.options['mayaPublishScene'] ]) panelComInstance = panelcom.PanelComInstance.instance() panelComInstance.setTotalExportSteps(totalSteps + 1) # Get original selection nodes = mc.ls(sl=True) # Get camera shape and parent transforms cameraShape = '' for node in nodes: if mc.nodeType(node) == 'camera': cameraShape = node else: cameraShapes = mc.listRelatives(node, allDescendents=True, type='camera') if len(cameraShapes) > 0: # We only care about one camera cameraShape = cameraShapes[0] if cameraShape == '': return None, 'No camera selected' cameraTransform = mc.listRelatives(cameraShape, type='transform', parent=True) cameraTransform = cameraTransform[0] if iAObj.options['cameraBake']: tmpCamComponents = mc.duplicate(cameraTransform, un=1, rc=1) if mc.nodeType(tmpCamComponents[0]) == 'transform': tmpCam = tmpCamComponents[0] else: tmpCam = mc.ls(tmpCamComponents, type='transform')[0] pConstraint = mc.parentConstraint(cameraTransform, tmpCam) try: mc.parent(tmpCam, world=True) except RuntimeError: print 'camera already in world space' mc.bakeResults(tmpCam, simulation=True, t=(float(iAObj.options['frameStart']), float(iAObj.options['frameEnd'])), sb=1, at=['tx', 'ty', 'tz', 'rx', 'ry', 'rz'], hi='below') mc.delete(pConstraint) cameraTransform = tmpCam panelComInstance.emitPublishProgressStep() if iAObj.options['cameraLock']: # Get original lock values so we can revert after exporting origCamLocktx = mc.getAttr('{0}.tx'.format(cameraTransform), l=True) origCamLockty = mc.getAttr('{0}.ty'.format(cameraTransform), l=True) origCamLocktz = mc.getAttr('{0}.tz'.format(cameraTransform), l=True) origCamLockrx = mc.getAttr('{0}.rx'.format(cameraTransform), l=True) origCamLockry = mc.getAttr('{0}.ry'.format(cameraTransform), l=True) origCamLockrz = mc.getAttr('{0}.rz'.format(cameraTransform), l=True) origCamLocksx = mc.getAttr('{0}.sx'.format(cameraTransform), l=True) origCamLocksy = mc.getAttr('{0}.sy'.format(cameraTransform), l=True) origCamLocksz = mc.getAttr('{0}.sz'.format(cameraTransform), l=True) # Lock transform mc.setAttr('{0}.tx'.format(cameraTransform), l=True) mc.setAttr('{0}.ty'.format(cameraTransform), l=True) mc.setAttr('{0}.tz'.format(cameraTransform), l=True) mc.setAttr('{0}.rx'.format(cameraTransform), l=True) mc.setAttr('{0}.ry'.format(cameraTransform), l=True) mc.setAttr('{0}.rz'.format(cameraTransform), l=True) mc.setAttr('{0}.sx'.format(cameraTransform), l=True) mc.setAttr('{0}.sy'.format(cameraTransform), l=True) mc.setAttr('{0}.sz'.format(cameraTransform), l=True) if iAObj.options['cameraMaya']: iAObj.setTotalSteps = False mayaComponents, message = GenericAsset.publishAsset(self, iAObj) publishedComponents += mayaComponents if iAObj.options['cameraAlembic']: mc.loadPlugin('AbcExport.so', qt=1) temporaryPath = HelpFunctions.temporaryFile(suffix='.abc') publishedComponents.append( FTComponent(componentname='alembic', path=temporaryPath)) alembicJobArgs = '' alembicJobArgs += '-fr {0} {1}'.format(iAObj.options['frameStart'], iAObj.options['frameEnd']) objCommand = '-root ' + cameraTransform + ' ' alembicJobArgs += ' ' + objCommand + '-file ' + temporaryPath alembicJobArgs += ' -step ' + str(iAObj.options['alembicSteps']) try: mc.AbcExport(j=alembicJobArgs) except: import traceback var = traceback.format_exc() return None, var panelComInstance.emitPublishProgressStep() if iAObj.options['cameraLock']: # Revert camera locks to original mc.setAttr('{0}.tx'.format(cameraTransform), l=origCamLocktx) mc.setAttr('{0}.ty'.format(cameraTransform), l=origCamLockty) mc.setAttr('{0}.tz'.format(cameraTransform), l=origCamLocktz) mc.setAttr('{0}.rx'.format(cameraTransform), l=origCamLockrx) mc.setAttr('{0}.ry'.format(cameraTransform), l=origCamLockry) mc.setAttr('{0}.rz'.format(cameraTransform), l=origCamLockrz) mc.setAttr('{0}.sx'.format(cameraTransform), l=origCamLocksx) mc.setAttr('{0}.sy'.format(cameraTransform), l=origCamLocksy) mc.setAttr('{0}.sz'.format(cameraTransform), l=origCamLocksz) if iAObj.options['cameraBake']: mc.delete(cameraTransform) # Set back original selection mc.select(nodes) panelComInstance.emitPublishProgressStep() if iAObj.options['mayaPublishScene']: iAObjCopy = self.getSceneSettingsObj(iAObj) sceneComponents, message = GenericAsset.publishAsset( self, iAObjCopy) publishedComponents += sceneComponents return publishedComponents, pubMessage
def publishAsset(self, iAObj=None): '''Publish the asset defined by the provided *iAObj*.''' publishedComponents = [] totalSteps = self.getTotalSteps(steps=[ iAObj.options['mayaBinary'], iAObj.options['alembic'], iAObj.options['mayaPublishScene'] ]) panelComInstance = panelcom.PanelComInstance.instance() panelComInstance.setTotalExportSteps(totalSteps) if iAObj.options['mayaBinary']: iAObj.setTotalSteps = False mayaComponents, message = GenericAsset.publishAsset(self, iAObj) publishedComponents += mayaComponents if iAObj.options['mayaPublishScene']: iAObjCopy = self.getSceneSettingsObj(iAObj) sceneComponents, message = GenericAsset.publishAsset( self, iAObjCopy) publishedComponents += sceneComponents if iAObj.options.get('alembic'): if iAObj.options.get('alembicExportMode') == 'Selection': nodes = mc.ls(sl=True, long=True) selectednodes = None else: selectednodes = mc.ls(sl=True, long=True) nodes = mc.ls(type='transform', long=True) objCommand = '' for n in nodes: objCommand = objCommand + '-root ' + n + ' ' mc.loadPlugin('AbcExport.so', qt=1) temporaryPath = HelpFunctions.temporaryFile(suffix='.abc') publishedComponents.append( FTComponent(componentname='alembic', path=temporaryPath)) alembicJobArgs = '' if iAObj.options.get('alembicUvwrite'): alembicJobArgs += '-uvWrite ' if iAObj.options.get('alembicWorldspace'): alembicJobArgs += '-worldSpace ' if iAObj.options.get('alembicWritevisibility'): alembicJobArgs += '-writeVisibility ' if iAObj.options.get('alembicAnimation'): alembicJobArgs += '-frameRange {0} {1} -step {2} '.format( iAObj.options['frameStart'], iAObj.options['frameEnd'], iAObj.options['alembicEval']) alembicJobArgs += ' ' + objCommand + '-file ' + temporaryPath mc.AbcExport(j=alembicJobArgs) if selectednodes: mc.select(selectednodes) panelComInstance.emitPublishProgressStep() return publishedComponents, 'Published GeometryAsset asset'
def publishAsset(self, iAObj=None): '''Publish the asset defined by the provided *iAObj*.''' panelComInstance = panelcom.PanelComInstance.instance() if hasattr(iAObj, 'customComponentName'): componentName = iAObj.customComponentName else: componentName = 'mayaBinary' channels = True preserveReferences = False constructionHistory = False constraints = False expressions = False shader = False if iAObj.options.get('mayaHistory'): constructionHistory = iAObj.options['mayaHistory'] if iAObj.options.get('mayaChannels'): channels = iAObj.options['mayaChannels'] if iAObj.options.get('mayaPreserveref'): preserveReferences = iAObj.options['mayaPreserveref'] if iAObj.options.get('mayaShaders'): shader = iAObj.options['mayaShaders'] if iAObj.options.get('mayaConstraints'): constraints = iAObj.options['mayaConstraints'] if iAObj.options.get('mayaExpressions'): expressions = iAObj.options['mayaExpressions'] if iAObj.options.get('exportMode') == 'Selection': exportSelectedMode = True exportAllMode = False else: exportSelectedMode = False exportAllMode = True publishedComponents = [] temporaryPath = HelpFunctions.temporaryFile(suffix='.mb') publishedComponents.append( FTComponent(componentname=componentName, path=temporaryPath)) mc.file(temporaryPath, op='v=0', typ='mayaBinary', preserveReferences=preserveReferences, constructionHistory=constructionHistory, channels=channels, constraints=constraints, expressions=expressions, shader=shader, exportSelected=exportSelectedMode, exportAll=exportAllMode, force=True) dependenciesVersion = [] dependencies = mc.ls(type='ftrackAssetNode') for dependency in dependencies: dependencyAssetId = mc.getAttr('{0}.assetId'.format(dependency)) if dependencyAssetId: dependencyVersion = ftrack.AssetVersion(dependencyAssetId) dependenciesVersion.append(dependencyVersion) currentVersion = ftrack.AssetVersion(iAObj.assetVersionId) currentVersion.addUsesVersions(versions=dependenciesVersion) panelComInstance.emitPublishProgressStep() return publishedComponents, 'Published ' + iAObj.assetType + ' asset'
def publishAsset(self, iAObj=None): '''Publish the asset defined by the provided *iAObj*.''' publishedComponents = [] totalSteps = self.getTotalSteps( steps=[ iAObj.options['houdiniNodes'], iAObj.options['alembic'], iAObj.options['houdiniPublishScene'] ] ) panelComInstance = panelcom.PanelComInstance.instance() panelComInstance.setTotalExportSteps(totalSteps) objPath = hou.node('/obj') cam = hou.selectedNodes()[0] bcam = self.bakeCamAnim(cam, [iAObj.options['frameStart'], iAObj.options['frameEnd']]) if iAObj.options['houdiniNodes']: temporaryPath = HelpFunctions.temporaryFile(suffix='.hip') publishedComponents.append( FTComponent( componentname='houdiniNodes', path=temporaryPath ) ) bcam.parent().saveChildrenToFile( [bcam], [], temporaryPath) panelComInstance.emitPublishProgressStep() if iAObj.options.get('houdiniPublishScene'): iAObjCopy = self.getSceneSettingsObj(iAObj) sceneComponents, message = GenericAsset.publishAsset( self, iAObjCopy ) publishedComponents += sceneComponents if iAObj.options.get('alembic'): ''' Export Alembic''' temporaryPath = HelpFunctions.temporaryFile(suffix='.abc') publishedComponents.append( FTComponent( componentname='alembic', path=temporaryPath ) ) # Create Rop Net ropNet = objPath.createNode('ropnet') abcRopnet = ropNet.createNode('alembic') if iAObj.options.get('alembicAnimation'): # Check Alembic for animation option abcRopnet.parm('trange').set(1) for i, x in enumerate( ['frameStart', 'frameEnd', 'alembicEval']): abcRopnet.parm('f%d' % (i + 1)).deleteAllKeyframes() abcRopnet.parm('f%d' % (i + 1)).set(iAObj.options[x]) else: abcRopnet.parm('trange').set(0) abcRopnet.parm('filename').set(temporaryPath) abcRopnet.parm('root').set(bcam.parent().path()) abcRopnet.parm('objects').set(bcam.path()) abcRopnet.parm('format').set('hdf5') abcRopnet.render() ropNet.destroy() panelComInstance.emitPublishProgressStep() bcam.destroy() return publishedComponents, 'Published CameraAsset asset'
def publishAsset(self, iAObj=None): '''Publish the asset defined by the provided *iAObj*.''' publishedComponents = [] totalSteps = self.getTotalSteps( steps=[ iAObj.options['houdiniNodes'], iAObj.options['alembic'], iAObj.options['houdiniPublishScene'] ] ) panelComInstance = panelcom.PanelComInstance.instance() panelComInstance.setTotalExportSteps(totalSteps) if iAObj.options['houdiniNodes']: houdiniComponents, message = GenericAsset.publishAsset( self, iAObj ) publishedComponents += houdiniComponents if iAObj.options.get('houdiniPublishScene'): iAObjCopy = self.getSceneSettingsObj(iAObj) sceneComponents, message = GenericAsset.publishAsset( self, iAObjCopy ) publishedComponents += sceneComponents if iAObj.options.get('alembic'): ''' Export Alembic''' temporaryPath = HelpFunctions.temporaryFile(suffix='.abc') publishedComponents.append( FTComponent( componentname='alembic', path=temporaryPath ) ) objPath = hou.node('/obj') # Selection Objects Set if iAObj.options.get('alembicExportMode') == 'Selection': selectednodes = hou.selectedNodes() objects = ' '.join([x.path() for x in selectednodes]) else: selectednodes = objPath.glob('*') objects = '*' # Create Rop Net ropNet = objPath.createNode('ropnet') print ropNet.path() abcRopnet = ropNet.createNode('alembic') if iAObj.options.get('alembicAnimation'): # Check Alembic for animation option abcRopnet.parm('trange').set(1) for i, x in enumerate( ['frameStart', 'frameEnd', 'alembicEval']): abcRopnet.parm('f%d' % (i + 1)).deleteAllKeyframes() abcRopnet.parm('f%d' % (i + 1)).set(iAObj.options[x]) else: abcRopnet.parm('trange').set(0) abcRopnet.parm('filename').set(temporaryPath) abcRopnet.parm('root').set(selectednodes[0].parent().path()) abcRopnet.parm('objects').set(objects) abcRopnet.parm('format').set('hdf5') abcRopnet.render() ropNet.destroy() panelComInstance.emitPublishProgressStep() return publishedComponents, 'Published GeometryAsset asset'
def publishAsset(n, assetName, content, comment, shot, currentTask): header = getHeaderKnob(n) if not currentTask: header.setMessage('Could not find current task', 'warning') else: publishProgress = nuke.ProgressTask('Publishing assets') publishProgress.setProgress(0) currentTaskId = currentTask.getId() assetType = n['ftrackassettype'].value() publishProgress.setMessage('Validating asset types') try: ftrack.AssetType(assetType) except ftrack.FTrackError: header.setMessage( 'No Asset type with short name "{0}" found. Contact your ' 'system administrator to add it.'.format(assetType), 'warning') return publishProgress.setMessage('Creating new version') asset = shot.createAsset(assetName, assetType) assetVersion = asset.createVersion(comment=comment, taskid=currentTaskId) if assetType in ['img', 'cam', 'geo', 'render']: if assetType == 'img': imgAsset = nukeassets.ImageSequenceAsset() publishedComponents = imgAsset.publishContent( content, assetVersion, progressCallback=publishProgress.setProgress) elif assetType == 'cam': camAsset = nukeassets.CameraAsset() publishedComponents = camAsset.publishContent( content, assetVersion, progressCallback=publishProgress.setProgress) elif assetType == 'geo': geoAsset = nukeassets.GeometryAsset() publishedComponents = geoAsset.publishContent( content, assetVersion, progressCallback=publishProgress.setProgress) elif assetType == 'render': renderAsset = nukeassets.RenderAsset() publishedComponents = renderAsset.publishContent( content, assetVersion, progressCallback=publishProgress.setProgress) if n['fscript'].value(): if n['fcopy'].value(): temporaryPath = HelpFunctions.temporaryFile(suffix='.nk') nuke.scriptSave(temporaryPath) mainPath = temporaryPath else: if nuke.Root().name() == 'Root': tmp_script = tempfile.NamedTemporaryFile(suffix='.nk') curScript = nuke.toNode("root").name() nuke.scriptSaveAs(tmp_script.name) mainAbsPath = tmp_script.name else: mainAbsPath = nuke.root()['name'].value() mainPath = mainAbsPath publishedComponents.append( FTComponent(componentname='nukescript', path=mainPath)) if publishedComponents: pubObj = FTAssetObject(assetVersionId=assetVersion.getId()) connector.Connector.publishAssetFiles( publishedComponents, assetVersion, pubObj, copyFiles=n['fcopy'].value(), progressCallback=publishProgress.setProgress) else: header.setMessage("Can't publish this assettype yet", 'info') return publishProgress.setMessage('Setting up version dependencies') dependencies = get_dependencies() if dependencies: for name, version in dependencies.items(): assetVersion.addUsesVersions(versions=version) assetVersion.publish() publishProgress.setProgress(100) header.setMessage('Asset published!')