def export(dir, show, elType, name=None, sequence=None, shot=None, clipName=None, work=False, release=False): if not os.path.isdir(dir): raise ValueError('Not a directory: {}'.format(dir)) el = Element(name, elType, show=show, sequence=sequence, shot=shot, clipName=clipName) if not el.exists(): raise ValueError('Given element does not exist') date = str(env.getCreationInfo(format=False)[1].date()) if work: finalDest = os.path.join(dir, 'work_' + el._rawId + '_' + date) if not os.path.exists(finalDest): os.makedirs(finalDest) fileutils.relativeCopyTree(el.work_path, finalDest) if release: finalDest = os.path.join(dir, 'release_' + el._rawId + '_' + date) if not os.path.exists(finalDest): os.makedirs(finalDest) fileutils.relativeCopyTree(el.release_path, finalDest)
def importAsset(): element = Element.fromPk(hxenv.getEnvironment('element')) if not element: container = Show.fromPk(hxenv.getEnvironment('show')) else: container = element.parent dialog = PublishedAssetBrowser( container, parent=QApplication.instance().activeWindow()) ret = dialog.exec_() if ret == QDialog.Accepted and dialog.selectedPf: if dialog.selectedPf.file_path: fs = FrameSequence(dialog.selectedPf.file_path) if fs.isValid(): read = nkutils.read('{} {}-{}'.format( dialog.selectedPf.file_path, fs.first(), fs.last())) else: read = nkutils.read(dialog.selectedPf.file_path) nkutils.updateReadWithElementInfo( read, Element.fromPk(dialog.selectedPf.elementId), dialog.selectedPf)
def importEl(dir, elType, name=None, sequence=None, shot=None, clipName=None, overwriteOption=0): """Imports the files in the given directory into an element's work directory. This element either already exists (based on name/elType/sequence/shot) or a new one will be made with the given parameters. Args: dir (str): Path to the directory to import files from into the element name (str): The name of the element to import to/create. elType (str): The element type of the element to import to/create. sequence (int, optional): The sequence number of the element to import to/create. Defaults to a show-level element. shot (int, optional): The shot number of the element to import to/create. Defaults to a show-level element. clipName (str, optional): The clip name of the specified shot number where the element will imported to/created in. overwriteOption (int, optional): The action to take when encountering files of the same name that already exist when importing into an already existing element. 0: DEFAULT. Duplicate files will be overwritten by the incoming source. 1: Version up. Incoming source files will be appended with a number. 2: Skip. Incoming source files will not be imported if they are duplicates. Raises: ImportError: If the specified directory does not exist or is not a directory. """ if not os.path.isdir(dir): raise ImportError('Not a directory: {}'.format(dir)) el = Element(name, elType, show=env.getEnvironment('show'), sequence=sequence, shot=shot, clipName=clipName, makeDirs=True) if not el.exists(): el.insert() fileutils.relativeCopyTree(dir, el.work_path, overwriteOption)
def mke(elType, name, sequence=None, shot=None, clipName=None): if name == '-': name = None el = Element(name, elType, sequence=sequence, shot=shot, clipName=clipName, makeDirs=True) if el.insert(): print 'Successfully created element {}'.format(el) return True else: raise DatabaseError('Failed to create element. Does it already exist?')
def knobChanged(): if nuke.thisNode().Class() == 'Read': knob = nuke.thisNode().knob('file') pf = PublishedFile.fromPath(knob.value()) if pf: nkutils.updateReadWithElementInfo(nuke.thisNode(), Element.fromPk(pf.elementId), pf)
def get(elType, name=None, sequence=None, shot=None): if name == '-': name = None element = Element(name, elType, show=env.getShow(), sequence=sequence, shot=shot) if not element: raise DatabaseError('Element doesn\'t exist (Check for typos in the name, or make a new element)') env.setEnvironment('element', element.id) print 'Working on {}'.format(element)
def guiStartup(): print 'Initializing Helix Nuke GUI...' from helix import Element, Show, Sequence, Shot, hxenv from helix.api.exceptions import EnvironmentError import helix.api.nuke.plugin as plugin import nuke helixRoot = nuke.menu('Nuke').addMenu('Helix') helixRoot.addCommand('Asset/Import...', plugin.importAsset) # File browser quick links try: element = Element.fromPk(hxenv.getEnvironment('element')) if element: nuke.addFavoriteDir(name='ASSET', directory=element.work_path) os.chdir(element.work_path) container = element.parent while not isinstance(container, Show): nuke.addFavoriteDir( name=container.__class__.__name__.upper(), directory=container.work_path) container = container.parent nuke.addFavoriteDir(name='SHOW', directory=container.work_path) print 'Done' except EnvironmentError: print 'Could not initialize Nuke for Helix without an asset' projDir = nuke.Root().knob('project_directory').value() if projDir: os.chdir(projDir)
def getWorkingElement(): element = getEnvironment('element', silent=True) if element: from helix import Element return Element.fromPk(element)