def import_all_gizmos(): session = ftrack_connect.session.get_shared_session() task = session.query('select parent.id from Task ' 'where id is "{0}"'.format( os.environ["FTRACK_TASKID"])).one() versions = session.query('AssetVersion where asset.parent.id is "{0}" and' ' asset.type.short is "nuke_gizmo"'.format( task["parent"]["id"])) # Collect all components. components = [] for version in get_latest_versions(versions): components.extend(version["components"]) # Collect all new components new_components = [] for component in components: node_exists = nuke.exists( HelpFunctions.safeString(component["version"]["asset"]["name"]) + "_" + HelpFunctions.safeString(component["name"])) if not node_exists: new_components.append(component) progress_bar = ProgressBar() progress_bar.show() for progress in import_components(components): progress_bar.bar.setValue(progress * 100) progress_bar.deleteLater()
def changeVersion(self, iAObj=None, applicationObject=None): n = nuke.toNode(HelpFunctions.safeString(applicationObject)) n['file'].setValue( HelpFunctions.safeString( nukecon.Connector.windowsFixPath(iAObj.filePath))) self.setFTab(n, iAObj) return True
def getUniqueSceneName(assetName): assetName = assetName res = nuke.toNode(HelpFunctions.safeString(assetName)) if res: i = 0 while res: uniqueAssetName = assetName + str(i) res = nuke.toNode(HelpFunctions.safeString(uniqueAssetName)) i = i + 1 return uniqueAssetName else: return assetName
def importAsset(self, iAObj=None): resultingNode = nuke.createNode("ReadGeo2", inpanel=False) resultingNode['file'].setValue( HelpFunctions.safeString( nukecon.Connector.windowsFixPath(iAObj.filePath))) resultingNode['name'].setValue( HelpFunctions.safeString(iAObj.assetName)) self.addFTab(resultingNode) self.setFTab(resultingNode, iAObj) return 'Imported geo asset'
def importAsset(self, iAObj=None): '''Import asset as new node.''' resultingNode = nuke.createNode('Read', inpanel=False) resultingNode['name'].setValue( HelpFunctions.safeString(iAObj.assetName) + '_' + HelpFunctions.safeString(iAObj.componentName)) resultingNode['file'].fromUserText( HelpFunctions.safeString(iAObj.filePath)) self.addFTab(resultingNode) self.setFTab(resultingNode, iAObj)
def getUniqueSceneName(assetName): assetName = assetName for n in hou.node('/').allSubChildren(): if n.name().startswith(HelpFunctions.safeString(assetName)): if n: i = 0 while n: uniqueAssetName = assetName + str(i) if n.name().startswith( HelpFunctions.safeString(uniqueAssetName)): i = i + 1 return uniqueAssetName else: return assetName
def getMetaData(nodeName): n = nuke.toNode(HelpFunctions.safeString(nodeName)) metaData = [] metaData.append(('res_x', str(n.width()))) metaData.append(('res_y', str(n.height()))) return metaData
def importAsset(self, iAObj=None): '''Create nuke read node from *iAObj.''' if iAObj.filePath.endswith('nk'): nuke.nodePaste(iAObj.filePath) return else: resultingNode = nuke.createNode('Read', inpanel=False) resultingNode['name'].setValue( HelpFunctions.safeString(iAObj.assetName) + '_' + HelpFunctions.safeString(iAObj.componentName)) self.addFTab(resultingNode) # Compute frame range # TODO: Store these attributes on the component for easy access. resultingNode['file'].fromUserText( HelpFunctions.safeString(iAObj.filePath)) start, end = self.getStartEndFrames(iAObj) resultingNode['first'].setValue(start) resultingNode['origfirst'].setValue(start) resultingNode['last'].setValue(end) resultingNode['origlast'].setValue(end) proxyPath = '' assetVersion = ftrack.AssetVersion(iAObj.assetVersionId) try: proxyPath = assetVersion.getComponent(name='proxy').getImportPath() except: pass try: proxyPath = assetVersion.getComponent(name=iAObj.componentName + '_proxy').getImportPath() except: pass if proxyPath != '': resultingNode['proxy'].fromUserText(proxyPath) self.setFTab(resultingNode, iAObj) return 'Imported %s asset' % iAObj.componentName
def setNodeColor(applicationObject='', latest=True): # Green RGB 20, 161, 74 # Orange RGB 227, 99, 22 latestColor = int('%02x%02x%02x%02x' % (20, 161, 74, 255), 16) oldColor = int('%02x%02x%02x%02x' % (227, 99, 22, 255), 16) n = nuke.toNode(HelpFunctions.safeString(applicationObject)) if latest: n.knob("note_font_color").setValue(latestColor) else: n.knob("note_font_color").setValue(oldColor)
def changeVersion(self, iAObj=None, applicationObject=None): n = nuke.toNode(HelpFunctions.safeString(applicationObject)) #print assetVersionId proxyPath = '' try: proxyPath = ftrack.AssetVersion(iAObj.assetVersionId).getComponent( name='proxy').getImportPath() except: print 'No proxy' n['file'].fromUserText(HelpFunctions.safeString(iAObj.filePath)) if proxyPath != '': n['proxy'].fromUserText(proxyPath) start, end = self.getStartEndFrames(iAObj) n['first'].setValue(start) n['origfirst'].setValue(start) n['last'].setValue(end) n['origlast'].setValue(end) self.setFTab(n, iAObj) return True
def publishContent(self, content, assetVersion, progressCallback=None): publishedComponents = [] for c in content: filename = c[0] componentName = c[1] sequenceComponent = FTComponent() start = int(float(c[2])) end = int(float(c[3])) if not start - end == 0: sequence_format = u'{0} [{1}-{2}]'.format(filename, start, end) else: sequence_format = u'{0}'.format(filename, start) sequenceIdentifier = sequence_format metaData = [] if not '_proxy' in componentName: metaData.append(('img_main', 'True')) for meta in c[5]: metaData.append((meta[0], meta[1])) sequenceComponent.componentname = componentName sequenceComponent.path = sequenceIdentifier sequenceComponent.metadata = metaData publishedComponents.append(sequenceComponent) try: node = nuke.toNode(HelpFunctions.safeString(content[0][4])) thumbnail = Connector.createThumbNail(node) if thumbnail: publishedComponents.append( FTComponent(componentname='thumbnail', path=thumbnail)) except: print 'Failed to create thumbnail' import sys traceback.print_exc(file=sys.stdout) return publishedComponents
def changeVersion(self, iAObj=None, applicationObject=None): for n in hou.node('/').allSubChildren(): if n.name().startswith(applicationObject): if iAObj.componentName == 'alembic': n.parm('fileName').set( HelpFunctions.safeString(iAObj.filePath)) hou.hscript( "opparm -C {0} buildHierarchy (1)".format( n.path())) self.setFTab(n, iAObj) return True elif iAObj.componentName == 'houdiniNodes': results = n.glob('*') for del_n in results: del_n.destroy() n.loadChildrenFromFile(iAObj.filePath) n.setSelected(1) self.setFTab(n, iAObj) return True
def scan_for_new_assets(): '''Scan scene for outdated asset versions.''' allAssets = connector.Connector.getAssets() message = '' check_items = [] scanned_ftrack_nodes = [] for ftrack_node in allAssets: ftrack_node = ftrack_node[1] n = nuke.toNode(HelpFunctions.safeString(ftrack_node)) ftrack_asset_version_id_url = n.knob('assetVersionId').value() url = urlparse.urlparse(ftrack_asset_version_id_url) query = urlparse.parse_qs(url.query) entityType = query.get('entityType')[0] asset_version_id = url.netloc component_name = n.knob('componentName').value() if asset_version_id is None: nuke.message( 'FTrack node "{0}" does not contain data!'.format(ftrack_node)) continue new_item = { 'asset_version_id': asset_version_id, 'component_name': component_name } check_items.append(new_item) scanned_ftrack_nodes.append(ftrack_node) if scanned_ftrack_nodes: import ftrack_api session = ftrack_api.Session(auto_connect_event_hub=False, plugin_paths=None) scanner = ftrack_connect.asset_version_scanner.Scanner( session=session, result_handler=( lambda result: ftrack_connect.util.invoke_in_main_thread( handle_scan_result, result, scanned_ftrack_nodes))) scanner.scan(check_items)
def setFTab(self, resultingNode, iAObj): componentId = ftrack.Component( iAObj.componentId).getEntityRef() assetVersionId = ftrack.AssetVersion( iAObj.assetVersionId).getEntityRef() components = { 'componentId': HelpFunctions.safeString(componentId), 'componentName': HelpFunctions.safeString(iAObj.componentName), 'assetVersionId': HelpFunctions.safeString(assetVersionId), 'assetVersion': HelpFunctions.safeString(iAObj.assetVersion), 'assetName': HelpFunctions.safeString(iAObj.assetName), 'assetType': HelpFunctions.safeString(iAObj.assetType), 'assetId': HelpFunctions.safeString(iAObj.assetId) } for comp in components: resultingNode.parm(comp).set(components[comp])
def publishContent(self, content, assetVersion, progressCallback=None): '''Return components to publish.''' components = [] for row in content: filename = row[0] componentName = row[1] components.append( FTComponent(componentname=componentName, path=filename)) try: node = nuke.toNode(HelpFunctions.safeString(content[0][4])) thumbnail = Connector.createThumbNail(node) if thumbnail: components.append( FTComponent(componentname='thumbnail', path=thumbnail)) except Exception: pass return components
def setFTab(self, resultingNode, iAObj): componentId = ftrack.Component(iAObj.componentId).getEntityRef() assetVersionId = ftrack.AssetVersion( iAObj.assetVersionId).getEntityRef() resultingNode.knob('assetId').setValue( HelpFunctions.safeString(iAObj.assetId)) resultingNode.knob('componentId').setValue( HelpFunctions.safeString(componentId)) resultingNode.knob('componentName').setValue( HelpFunctions.safeString(iAObj.componentName)) resultingNode.knob('assetVersionId').setValue( HelpFunctions.safeString(assetVersionId)) resultingNode.knob('assetVersion').setValue( HelpFunctions.safeString(iAObj.assetVersion)) resultingNode.knob('assetName').setValue( HelpFunctions.safeString(iAObj.assetName)) resultingNode.knob('assetType').setValue( HelpFunctions.safeString(iAObj.assetType))
def removeObject(applicationObject=''): deleteMeNode = nuke.toNode(HelpFunctions.safeString(applicationObject)) nuke.delete(deleteMeNode)
def changeVersion(self, iAObj=None, applicationObject=None): '''Change current version of the give *iAObj* and *applicationObject*.''' n = nuke.toNode(HelpFunctions.safeString(applicationObject)) n['file'].fromUserText(HelpFunctions.safeString(iAObj.filePath)) self.setFTab(n, iAObj) return True
def ftrackPublishKnobChanged(forceRefresh=False, g=None): g = g or nuke.thisNode() if 'ftable' in g.knobs(): header = getHeaderKnob(g) nodeAssetType = '' if nuke.thisKnob().name() in ['inputChange', 'fscript' ] or forceRefresh == True: thisNodeName = g['name'].value() g = nuke.toNode(HelpFunctions.safeString(thisNodeName)) # Add new labels cmdString = '' assetType = None availableAssetTypes = [''] inputMissmatch = None tableWidget = g['ftable'].getObject().tableWidget tableWidget.setRowCount(0) components = [] for inputNode in range(g.inputs()): inNode = g.input(inputNode) if inNode: if inNode.Class() in ['Read', 'Write']: nodeAssetType = 'img' elif inNode.Class() in ['WriteGeo']: nodeAssetType = 'geo' else: nodeAssetType = '' if not assetType: assetType = nodeAssetType if assetType != nodeAssetType: inputMissmatch = True if nodeAssetType == 'img': fileComp = str(inNode['file'].value()) proxyComp = str(inNode['proxy'].value()) nameComp = str(inNode['name'].value()).strip() if inNode.Class() == 'Read': first = str(inNode['first'].value()) last = str(inNode['last'].value()) if first == '0.0' and last == '0.0': first = str( int(nuke.root().knob( "first_frame").value())) last = str( int(nuke.root().knob( "last_frame").value())) availableAssetTypes = ['img', 'render'] elif inNode.Class() == 'Write': # use the timeline to define the amount of frames first = str( int(nuke.root().knob("first_frame").value())) last = str( int(nuke.root().knob("last_frame").value())) # then in case check if the limit are set if inNode['use_limit'].value(): first = str(inNode['first'].value()) last = str(inNode['last'].value()) # always check how many frames are actually available frames = inNode['file'].value() try: # Try to collect the sequence prefix, padding # and extension. If this fails with a ValueError # we are probably handling a non-sequence file. # If so rely on the first_frame and last_frame # of the root node. prefix, padding, extension = frames.split('.') except ValueError: FnAssetAPI.logging.debug( 'Could not determine prefix, padding ' 'and extension from "".'.format(frames)) availableAssetTypes = ['render'] else: root = os.path.dirname(prefix) files = glob.glob('{0}/*.{1}'.format( root, extension)) collections = clique.assemble(files) for collection in collections[0]: if prefix in collection.head: indexes = list(collection.indexes) first = str(indexes[0]) last = str(indexes[-1]) break availableAssetTypes = ['img'] try: compNameComp = inNode['fcompname'].value() except: compNameComp = '' if compNameComp == '': compNameComp = nameComp components.append( (fileComp, compNameComp, first, last, nameComp)) if proxyComp != '': components.append( (proxyComp, compNameComp + '_proxy', first, last, nameComp)) elif nodeAssetType == 'geo': fileComp = str(inNode['file'].value()) nameComp = str(inNode['name'].value()).strip() first = str(inNode['first'].value()) last = str(inNode['last'].value()) if first == '0.0' and last == '0.0': first = str( int(nuke.root().knob("first_frame").value())) last = str( int(nuke.root().knob("last_frame").value())) try: compNameComp = inNode['fcompname'].value() except: compNameComp = '' if compNameComp == '': compNameComp = nameComp components.append( (fileComp, compNameComp, first, last, nameComp)) availableAssetTypes = ['geo', 'cam'] rowCount = len(components) tableWidget.setRowCount(rowCount) if len(components) == 0: g.knob('pknob').setEnabled(False) else: g.knob('pknob').setEnabled(True) l = [x[1] for x in components] wodup = list(set(l)) if len(l) != len(wodup): g.knob('pknob').setEnabled(False) header.setMessage('Components can not have the same name', 'warning') rowCntr = 0 for comp in components: cb = QtWidgets.QCheckBox('') cb.setChecked(True) tableWidget.setCellWidget(rowCntr, 0, cb) componentItem = QtWidgets.QTableWidgetItem() componentItem.setText(comp[0]) componentItem.setToolTip(comp[0]) tableWidget.setItem(rowCntr, 1, componentItem) componentItem = QtWidgets.QTableWidgetItem() componentItem.setText(comp[1]) componentItem.setToolTip(comp[1]) tableWidget.setItem(rowCntr, 2, componentItem) try: fileCurrentFrame = nukescripts.replaceHashes( comp[0]) % int(float(comp[2])) except: print 'File is not sequence' fileCurrentFrame = comp[0] if os.path.isfile(fileCurrentFrame): fileExist = 'T' else: fileExist = 'F' componentItem = QtWidgets.QTableWidgetItem() if fileExist == 'T': componentItem.setBackground(QtGui.QColor(20, 161, 74)) else: componentItem.setBackground(QtGui.QColor(227, 99, 22)) componentItem.setToolTip(fileExist) tableWidget.setItem(rowCntr, 4, componentItem) componentItem = QtWidgets.QTableWidgetItem() componentItem.setText(comp[2]) componentItem.setToolTip(comp[2]) tableWidget.setItem(rowCntr, 5, componentItem) componentItem = QtWidgets.QTableWidgetItem() componentItem.setText(comp[3]) componentItem.setToolTip(comp[3]) tableWidget.setItem(rowCntr, 6, componentItem) componentItem = QtWidgets.QTableWidgetItem() componentItem.setText(comp[4]) componentItem.setToolTip(comp[4]) tableWidget.setItem(rowCntr, 3, componentItem) rowCntr += 1 g['ftrackassettype'].setValues(availableAssetTypes) if inputMissmatch: tableWidget.setRowCount(0) g['ftrackassettype'].setValues(['Missmatch inputs']) if cmdString == '': cmdString = 'No inputs connected' assetEnums = ['New'] if nodeAssetType != '': # assets = connector.Connector.objectById(os.environ['FTRACK_SHOTID']).getAssets(assetTypes=[g['ftrackassettype'].value()]) pubto = g.knob('fpubto').getObject().targetTask assets = connector.Connector.objectById(pubto).getAssets( assetTypes=[g['ftrackassettype'].value()]) assets = sorted(assets, key=lambda entry: entry.getName().lower()) assetEnums = assetEnums + [ HelpFunctions.safeString(x.getName()) for x in assets ] FnAssetAPI.logging.info(assetEnums) g['fassetnameexisting'].setValues(assetEnums) g = nuke.toNode(HelpFunctions.safeString(thisNodeName)) g.begin() # Add more inputs if full realInputCount = 0 for inputNode in range(g.inputs()): if g.input(inputNode): realInputCount += 1 if realInputCount == g.maxInputs(): inputNode = nuke.createNode("Input", inpanel=False) g.end() elif nuke.thisKnob().name() == 'ftrackassettype': nodeAssetType = g['ftrackassettype'].value() #print nodeAssetType assetEnums = ['New'] if nodeAssetType != '' and nodeAssetType != 'Missmatch inputs': # assets = connector.Connector.objectById(os.environ['FTRACK_SHOTID']).getAssets(assetTypes=[nodeAssetType]) pubto = g.knob('fpubto').getObject().targetTask assets = connector.Connector.objectById(pubto).getAssets( assetTypes=[nodeAssetType]) assetEnums = assetEnums + [ HelpFunctions.safeString(x.getName()) for x in assets ] g['fassetnameexisting'].setValues(assetEnums)
def selectObject(applicationObject='', clearSelection=True): if clearSelection: nukescripts.clear_selection_recursive() n = nuke.toNode(HelpFunctions.safeString(applicationObject)) n.knob('selected').setValue(True)
def import_components(components): for new_component in components: component = ftrack.Component(new_component["id"]) assetversion = component.getVersion() asset = assetversion.getAsset() assettype = asset.getType() # Create node resultingNode = nuke.createNode('Read', inpanel=False) resultingNode['name'].setValue( HelpFunctions.safeString(asset.getName()) + '_' + HelpFunctions.safeString(component.getName())) # Add Ftrack tab knobs = resultingNode.knobs().keys() if 'ftracktab' not in knobs: # Note: the tab is supposed to be existing as it gets created # through callback during the read and write nodes creation. # This check is to ensure corner cases are handled properly. tab = nuke.Tab_Knob('ftracktab', 'ftrack') resultingNode.addKnob(tab) btn = nuke.String_Knob('componentId') resultingNode.addKnob(btn) btn = nuke.String_Knob('componentName') resultingNode.addKnob(btn) btn = nuke.String_Knob('assetVersionId') resultingNode.addKnob(btn) btn = nuke.String_Knob('assetVersion') resultingNode.addKnob(btn) btn = nuke.String_Knob('assetName') resultingNode.addKnob(btn) btn = nuke.String_Knob('assetType') resultingNode.addKnob(btn) btn = nuke.String_Knob('assetId') resultingNode.addKnob(btn) # Setup node file_path = component.getResourceIdentifier() resultingNode['file'].fromUserText(HelpFunctions.safeString(file_path)) members = component.getMembers() frames = [int(member.getName()) for member in members] start = min(frames) end = max(frames) resultingNode['first'].setValue(start) resultingNode['origfirst'].setValue(start) resultingNode['last'].setValue(end) resultingNode['origlast'].setValue(end) resultingNode.knob('assetId').setValue( HelpFunctions.safeString(asset.getId())) resultingNode.knob('componentId').setValue( HelpFunctions.safeString(component.getEntityRef())) resultingNode.knob('componentName').setValue( HelpFunctions.safeString(component.getName())) resultingNode.knob('assetVersionId').setValue( HelpFunctions.safeString(assetversion.getEntityRef())) resultingNode.knob('assetVersion').setValue( HelpFunctions.safeString(str(assetversion.getVersion()))) resultingNode.knob('assetName').setValue( HelpFunctions.safeString(asset.getName())) resultingNode.knob('assetType').setValue( HelpFunctions.safeString(assettype.getShort()))