Ejemplo n.º 1
0
def updateAutowrite():
    for curNode in nuke.allNodes('Write'):
        tempPath = nuke.root()['name'].value()
        pathData = fxpipe.getPathData(tempPath)
        if 'shot' in tempPath:
            if 'AutoWrite' in curNode['name'].value():
                #width = curNode.width()
                #height = curNode.height()
                format = curNode.format().name().lower()
                colorspace = curNode['colorspace'].value()
                colorspace = colorspace.replace('default (', '')
                colorspace = colorspace.replace(')', '').lower()
                fileType = curNode['file_type'].value()
                ###########################################
                ## deal with the longer file types
                if fileType == 'jpeg': fileType = 'jpg'
                elif fileType == 'tiff': fileType = 'tif'
                elif fileType == 'targa': fileType = 'tga'
                ###########################################
                outputPath = tempPath.split('/')
                outputFile = outputPath[-1].split('.')[0]
                outputVersion = re.search('v[0-9]+', outputFile).group(0)
                outputShot = outputPath[7].lower()
                outputRez = outputPath[-2]
                newPath = '/'.join(outputPath[0:8])
                outputFormat = '%s_%s' % (format, colorspace)
                outputType = curNode['outputType'].value().lower()
                descriptor = curNode['descriptor'].value()
                if descriptor != '':
                    descriptor = '_%s' % (descriptor)
                aov = curNode['aov'].value()
                if aov != '':
                    aov = '_%s' % (aov)
                outputName = '%s%s_%s%s_%s' % (pathData['shot'], aov,
                                               outputType, descriptor,
                                               outputVersion)
                pathData = fxpipe.getPathData(nuke.root()['name'].value())
                writePath = nuke.filenameFilter(fxpipe.nukeOutPath)
                writePath = writePath.replace('[JOB]', pathData['job'])
                writePath = writePath.replace('[SEQ]', pathData['seq'])
                writePath = writePath.replace('[SHOT]', pathData['shot'])
                writePath = '%s/%s' % (nuke.filenameFilter(
                    fxpipe.jobPath), writePath)
                newPath = '%s/%s/%s_%s/%s_%s.####.%s' % (
                    writePath, outputName, outputFormat, fileType, outputName,
                    outputFormat, fileType)
                curNode['file'].setValue(newPath.replace(' ', '_'))
            #else:
            #    curNode['label'].setValue('Please save your script in the proper location')
            #    curNode['file'].setValue('')
            '''
Ejemplo n.º 2
0
def updateAutowrite():
    for curNode in nuke.allNodes('Write'):
        tempPath = nuke.root()['name'].value()
        pathData = fxpipe.getPathData(tempPath)
        if 'shot' in tempPath:
            if 'AutoWrite' in curNode['name'].value():
                #width = curNode.width()
                #height = curNode.height()
                format = curNode.format().name().lower()
                colorspace = curNode['colorspace'].value()
                colorspace = colorspace.replace ('default (','')
                colorspace = colorspace.replace (')','').lower()
                fileType = curNode['file_type'].value()
                ###########################################
                ## deal with the longer file types
                if fileType == 'jpeg': fileType = 'jpg'
                elif fileType == 'tiff': fileType = 'tif'
                elif fileType == 'targa': fileType = 'tga'
                ###########################################
                outputPath = tempPath.split('/')
                outputFile = outputPath[-1].split('.')[0]
                outputVersion = re.search('v[0-9]+',outputFile).group(0)
                outputShot = outputPath[7].lower()
                outputRez = outputPath[-2]
                newPath = '/'.join(outputPath[0:8])
                outputFormat = '%s_%s' % (format, colorspace)
                outputType = curNode['outputType'].value().lower()
                descriptor = curNode['descriptor'].value()
                if descriptor != '':
                    descriptor = '_%s' % (descriptor)
                aov = curNode['aov'].value()
                if aov != '':
                    aov = '_%s' % (aov)
                outputName = '%s%s_%s%s_%s' % (pathData['shot'], aov, outputType, descriptor, outputVersion)                
                pathData = fxpipe.getPathData(nuke.root()['name'].value())
                writePath = nuke.filenameFilter(fxpipe.nukeOutPath)
                writePath = writePath.replace('[JOB]',pathData['job'])
                writePath = writePath.replace('[SEQ]',pathData['seq'])
                writePath = writePath.replace('[SHOT]',pathData['shot'])
                writePath = '%s/%s' % (nuke.filenameFilter(fxpipe.jobPath), writePath)
                newPath = '%s/%s/%s_%s/%s_%s.####.%s' % (writePath, outputName,outputFormat, fileType, outputName, outputFormat, fileType)
                curNode['file'].setValue(newPath.replace(' ','_'))
            #else: 
            #    curNode['label'].setValue('Please save your script in the proper location')
            #    curNode['file'].setValue('') 
            '''
            
            '''          
def createWriteDirs(in_node):

    baseDir = os.path.dirname( nuke.filename(in_node) )
    viewTokenRE = re.compile( r'%V' )
    if viewTokenRE.search( baseDir ):
        nodeViews = nuke.thisNode()['views'].value().split()
        outDirs = [nuke.filenameFilter(viewTokenRE.sub(v, baseDir)) for v in nodeViews]
    else:
        outDirs = [nuke.filenameFilter(baseDir)]
    for outDir in outDirs:
        if not os.path.exists(outDir):
            print 'Creating output directory: %s' % outDir
            try:
                os.makedirs(outDir)
            except (OSError, IOError), e:
                import errno
                if e.errno != errno.EEXIST:
                    raise
def createWriteDirs(in_node):

    baseDir = os.path.dirname(nuke.filename(in_node))
    viewTokenRE = re.compile(r'%V')
    if viewTokenRE.search(baseDir):
        nodeViews = nuke.thisNode()['views'].value().split()
        outDirs = [
            nuke.filenameFilter(viewTokenRE.sub(v, baseDir)) for v in nodeViews
        ]
    else:
        outDirs = [nuke.filenameFilter(baseDir)]
    for outDir in outDirs:
        if not os.path.exists(outDir):
            print 'Creating output directory: %s' % outDir
            try:
                os.makedirs(outDir)
            except (OSError, IOError), e:
                import errno
                if e.errno != errno.EEXIST:
                    raise
Ejemplo n.º 5
0
    def _setOCIOSettingsOnRootNode(self):

        ocio_template = self.get_template("ocio_template")
        ocio_path = self.sgtk.paths_from_template(ocio_template, {})[0]
        ocio_path = ocio_path.replace(os.path.sep, "/")

        nuke.root().knob("colorManagement").setValue("OCIO")
        nuke.root().knob("OCIO_config").setValue("custom")
        if ocio_path != nuke.filenameFilter(
                nuke.root().knob("customOCIOConfigPath").value()
        ):  # only set the ocio path if it's not already set. Do not change it if it's the same path written for another platform
            nuke.root().knob("customOCIOConfigPath").setValue(ocio_path)
        # By convention, the scene_linear role is used as working space
        nuke.root().knob("workingSpaceLUT").setValue("scene_linear")
Ejemplo n.º 6
0
    def _setOCIOKnobDefaults(self):

        # Knob defaults by themselves dont seem to work correctly, they dont
        # intialize the viewer processes so we're also hitting this with
        # a big stick in the _setOCIOSettingsOnRootNode function and
        # essentially setting these defaults twice. Yay Nuke!

        ocio_path = os.getenv("OCIO_CONFIG")
        ocio_path = ocio_path.replace(os.path.sep, "/")
        ocio_path = nuke.filenameFilter(ocio_path)

        self.log_debug("Setting knob defaults for Root node OCIO settings.")
        nuke.knobDefault("Root.colorManagement", "OCIO")
        nuke.knobDefault("Root.OCIO_config", "custom")
        nuke.knobDefault("Root.customOCIOConfigPath", ocio_path)
Ejemplo n.º 7
0
    def _setOCIOSettingsOnRootNode(self):

        ocio_path = os.getenv("OCIO_CONFIG")
        ocio_path = ocio_path.replace(os.path.sep, "/")
        ocio_path = nuke.filenameFilter(ocio_path)

        colorManagementKnob = nuke.root().knob("colorManagement")
        OCIOconfigKnob = nuke.root().knob("OCIO_config")
        customOCIOConfigPathKnob = nuke.root().knob("customOCIOConfigPath")

        # If this is a new script, then set the knobs. This may seem redundant given that we also
        # set knob defaults, but nuke seems to need both to correctly load the
        # viewer processes.
        if nuke.root().knob("name").value() == '':
            # Set the color management to Nuke first. Setting it from 'Nuke'
            # to 'OCIO' seems to be what initializes the viewer processes.
            self.log_debug(
                "New script detected, setting Root node OCIO settings.")
            colorManagementKnob.setValue("Nuke")
            OCIOconfigKnob.setValue("custom")
            customOCIOConfigPathKnob.setValue(ocio_path)
            colorManagementKnob.setValue("OCIO")
        # for an existing script, check the settings and ask the user to change if incorrect
        elif colorManagementKnob.value() == 'OCIO' and \
          OCIOconfigKnob.value() == 'custom' and \
          customOCIOConfigPathKnob.value() == ocio_path:
            pass
        else:
            self.log_debug("Preseting user with dialog...")
            anwser = nuke.ask(
                'WARNING: Your OCIO settings do not match the correct settings for this project<p> \
                Nuke is currently using the %s OCIO config located in:<br><i>%s</i><p>\
                It is supposed to use the custom OCIO config for this project located in:<br><i>%s</i><p>\
                Do you want me to correct the OCIO settings?<br>Please be aware that changing the OCIO config \
                is going to reset all ocio nodes.' %
                (OCIOconfigKnob.value(), customOCIOConfigPathKnob.value(),
                 ocio_path))
            if anwser:
                self.log_debug(
                    "User accepted changes, setting Root node OCIO settings.")
                colorManagementKnob.setValue("Nuke")
                OCIOconfigKnob.setValue("custom")
                customOCIOConfigPathKnob.setValue(ocio_path)
                colorManagementKnob.setValue("OCIO")
            else:
                self.log_debug(
                    "User refused, keeping current Root node OCIO settings.")
Ejemplo n.º 8
0
    def _setOCIOSettingsOnRootNode(self):

        ocio_template = self.get_template("ocio_template")
        ocio_path = self.sgtk.paths_from_template(ocio_template, {})[0]
        ocio_path = ocio_path.replace(os.path.sep, "/")
        '''
        First case : the viewer process LUTs is set to 'Nuke Root LUTs'.
        In this case we assume the user has not intervened, Nuke is using it's default values
        So we change it to use the project ocio config without asking the user
        '''
        if nuke.root().knob("defaultViewerLUT").value() == 'Nuke Root LUTs':

            nuke.root().knob("defaultViewerLUT").setValue("OCIO LUTs")
            nuke.root().knob("OCIO_config").setValue("custom")
            nuke.root().knob("customOCIOConfigPath").setValue(ocio_path)
        '''
        Second case : the viewer process LUTs is configured to use OCIO Luts
        '''
        if nuke.root().knob("defaultViewerLUT").value() == 'OCIO LUTs':
            # if the ocio config is not set to custom or if the ocio config file path is not correct we ask the user if he allows us to correct it
            nuke_ocio_path = nuke.root().knob("customOCIOConfigPath").value()
            nuke_ocio_path = nuke.filenameFilter(
                nuke_ocio_path)  # for cross platform compatibility
            if nuke.root().knob("OCIO_config").value(
            ) != "custom" or nuke_ocio_path.lower() != ocio_path.lower():
                anwser = nuke.ask(
                    'Warning. Your OCIO settings do not match the correct settings for this project<p> \
                    Nuke is currently using the %s OCIO config located in:<br><i>%s</i><p>\
                    It is supposed to use the custom OCIO config for this project located in:<br><i>%s</i><p>\
                    Do you want me to correct the OCIO settings ?<br>Please be aware that changing the OCIO config is going to reset all ocio nodes.'
                    % (nuke.root().knob("OCIO_config").value(),
                       nuke.root().knob("customOCIOConfigPath").value(),
                       ocio_path))
                if anwser:
                    nuke.root().knob("defaultViewerLUT").setValue("OCIO LUTs")
                    nuke.root().knob("OCIO_config").setValue("custom")
                    nuke.root().knob("customOCIOConfigPath").setValue(
                        ocio_path)
Ejemplo n.º 9
0
    def action(self):


        readList =		[]
        writeList=		[]
        fbxList=		[]

        if os.path.exists(self.file.value() + '/') == False:
            os.makedirs(self.file.value())
            
        nuke.scriptSaveAs(self.file.value() + '/' + self.scriptName.value())

        readToCopy=		[]
        writeToCopy=  []
        self.scriptRoot = '''[file dirname [knob root.name]]'''

        DESTINATION = self.file.value()
        LAYERS =		DESTINATION + 'LAYERS/'
        FBX =			DESTINATION + 'GEO/'
        WRITE =			DESTINATION + 'WRITE/'	


        # Read	
        for n in nuke.allNodes('Read'):
            if n.knob('file').value() not in readList:
                if n.knob('disable').value() == False:
                    readList.append(nuke.filenameFilter(n.knob('file').value()))

        for p in readList:
            if os.path.exists(os.path.dirname(p)):
                for f in os.listdir(os.path.dirname(p)):
                    if os.path.splitext(f)[-1] == os.path.splitext(p)[-1]:

                        if len(f.split('.')[0]) == len(os.path.basename(p).split('.')[0]):
                            path = '/'.join([os.path.dirname(p),os.path.basename(f)])
                            if os.path.isfile(path):
                                readToCopy.append(path)






        #FBX
        for n in nuke.allNodes():
            if n.Class() in ['ReadGeo2','Camera2','Axis2','WriteGeo']:
                if n.knob('file').value():
                    if n.knob('file').value() not in fbxList:
                        if n.knob('disable').value() == False:
                            fbxList.append(nuke.filenameFilter(n.knob('file').value()))



        #Write
        '''
        for n in nuke.allNodes('Write'):
            if n.knob('file').value() not in writeList:
                if n.knob('disable').value() == False:
                    if n.knob('file').value() != '':
                        if os.path.isdir( os.path.dirname( n.knob('file').value() ) ):
                            writeList.append(nuke.filenameFilter(n.knob('file').value()))
        '''
        for p in writeList:
            if os.path.exists(os.path.dirname(p)):
                for f in os.listdir(os.path.dirname(p)):
                    if os.path.splitext(f)[-1] == os.path.splitext(p)[-1]:

                        if f.split('.')[0] == os.path.basename(p).split('.')[0]:
                            path = '/'.join([os.path.dirname(p),os.path.basename(f)])
                            if os.path.isfile(path):
                                writeToCopy.append(path)



        self.copyDic = {}
        for p in readToCopy:

            folder = os.path.dirname(p).split('/')[-1] + '/'

            if os.path.exists(LAYERS + folder) == False:
                os.makedirs(LAYERS + folder)
            self.copyDic[p] = [LAYERS + folder + os.path.basename(p),os.path.getsize(p)]



        for p in fbxList:



            if os.path.exists(FBX) == False:
                os.makedirs(FBX)

            #shutil.copy( p , FBX  + os.path.basename(p) )	
            self.copyDic[p] = [FBX	+ os.path.basename(p),os.path.getsize(p)]

        for p in writeToCopy:

            folder = os.path.dirname(p).split('/')[-1] + '/'

            if os.path.exists(WRITE + folder) == False:
                os.makedirs(WRITE + folder)

            #shutil.copy( p , WRITE + folder + os.path.basename(p) )
            self.copyDic[p] = [WRITE + folder + os.path.basename(p),os.path.getsize(p)]
        threading.Thread( None, self.action2 ).start()
Ejemplo n.º 10
0
    def action(self):


        readList =		[]
        writeList=		[]
        fbxList=		[]

        if os.path.exists(self.file.value() + '/') == False:
            os.makedirs(self.file.value())
            
        nuke.scriptSaveAs(self.file.value() + '/' + self.scriptName.value())

        readToCopy=		[]
        writeToCopy=  []
        fbxToCopy = []
        self.scriptRoot = '''[file dirname [knob root.name]]'''

        DESTINATION = self.file.value()
        LAYERS =		DESTINATION + 'LAYERS/'
        FBX =			DESTINATION + 'GEO/'
        WRITE =			DESTINATION + 'WRITE/'	


        # Read	
        for n in nuke.allNodes('Read'):
            if n.knob('file').value() not in readList:
                if n.knob('disable').value() == False:
                    readList.append(nuke.filenameFilter(n.knob('file').value()))

        for p in readList:
            if os.path.exists(os.path.dirname(p)):
                for f in os.listdir(os.path.dirname(p)):
                    if os.path.splitext(f)[-1] == os.path.splitext(p)[-1]:

                        if len(f.split('.')[0]) == len(os.path.basename(p).split('.')[0]):
                            path = '/'.join([os.path.dirname(p),os.path.basename(f)])
                            if os.path.isfile(path):
                                readToCopy.append(path)






        #FBX
        for n in nuke.allNodes():
            if n.Class() in ['ReadGeo2','Camera2','Axis2','WriteGeo']:
                if n.knob('file').value():
                    if n.knob('file').value() not in fbxList:
                        if n.knob('disable').value() == False:
                            fbxList.append(nuke.filenameFilter(n.knob('file').value()))

        for p in fbxList:
            if os.path.exists(os.path.dirname(p)):
                for f in os.listdir(os.path.dirname(p)):
                    if os.path.splitext(f)[-1] == os.path.splitext(p)[-1]:

                        if len(f.split('.')[0]) == len(os.path.basename(p).split('.')[0]):
                            path = '/'.join([os.path.dirname(p),os.path.basename(f)])
                            if os.path.isfile(path):
                                fbxToCopy.append(path)


        #Write
        '''
        for n in nuke.allNodes('Write'):
            if n.knob('file').value() not in writeList:
                if n.knob('disable').value() == False:
                    if n.knob('file').value() != '':
                        if os.path.isdir( os.path.dirname( n.knob('file').value() ) ):
                            writeList.append(nuke.filenameFilter(n.knob('file').value()))
        '''
        for p in writeList:
            if os.path.exists(os.path.dirname(p)):
                for f in os.listdir(os.path.dirname(p)):
                    if os.path.splitext(f)[-1] == os.path.splitext(p)[-1]:

                        if f.split('.')[0] == os.path.basename(p).split('.')[0]:
                            path = '/'.join([os.path.dirname(p),os.path.basename(f)])
                            if os.path.isfile(path):
                                writeToCopy.append(path)



        self.copyDic = {}
        for p in readToCopy:

            folder = os.path.dirname(p).split('/')[-1] + '/'

            if os.path.exists(LAYERS + folder) == False:
                os.makedirs(LAYERS + folder)
            self.copyDic[p] = [LAYERS + folder + os.path.basename(p),os.path.getsize(p)]



        for p in fbxToCopy:

            folder = os.path.dirname(p).split('/')[-1] + '/'
            if os.path.exists(FBX + folder ) == False:
                os.makedirs(FBX + folder)

            #shutil.copy( p , FBX  + os.path.basename(p) )	
            self.copyDic[p] = [FBX	+ folder + os.path.basename(p),os.path.getsize(p)]

        for p in writeToCopy:

            folder = os.path.dirname(p).split('/')[-1] + '/'

            if os.path.exists(WRITE + folder) == False:
                os.makedirs(WRITE + folder)

            #shutil.copy( p , WRITE + folder + os.path.basename(p) )
            self.copyDic[p] = [WRITE + folder + os.path.basename(p),os.path.getsize(p)]
        threading.Thread( None, self.action2 ).start()