def restartNuke():

    if nuke.ask('Are you sure you want to restart Nuke?'):

        scriptName = nuke.root().knob('name').getValue()

        subprocess_options = {"shell": True}

        separate_terminal_options = {
            "close_fds": True,
            "preexec_fn": os.setsid
        }

        if nuke.env['nukex'] == True:
            session = '--nukex'
        else:
            session = '--nuke'

        if 'REZ_VOLT_SESSION_ROOT' in os.environ:
            subprocess_options.update(separate_terminal_options)

        if os.path.isfile(scriptName):
            nuke.scriptSave()
            launch_cmd = '{} {} {}'.format(sys.executable, session, scriptName)
            subprocess.Popen(launch_cmd, **subprocess_options)
            nuke.modified(False)
            nuke.scriptExit()
        else:
            nuke.scriptNew('')
            nuke.modified(False)
            nuke.scriptExit()
Example #2
0
def restartNuke():
    """
    Restarts Nuke.
    :return: None
    """
    # https://community.foundry.com/discuss/topic/135555/
    nuke.scriptNew('')
    nuke.modified(False)  # doesn't ask for saving
    nuke.scriptExit()
Example #3
0
def exit_application(application="maya"):
    """
    This script is like close_script_job but it is much more aggressive and 
    forces the current application to shut off
    """
    if application == "maya":
        closeApp = functools.partial(cmds.quit(f=True))
        cmds.scriptJob(runOnce=True, e=['idle', closeApp])
    elif application == "nuke":
        nuke.scriptExit()
    elif application == "houdini":
        hou.exit()
Example #4
0
def runScript(filepath):
    nuke.scriptOpen(filepath)
    r3d = nuke.toNode('Read1')
    r3d.setXYpos(730, -451)
    nuke.toNode('HieroData').setXYpos(730, -359)
    jpg = nuke.toNode('Read2')
    if jpg != None:
        print "has no jpg-read"
        jpg.setXYpos(840, -457)
        nuke.toNode('HieroData1').setXYpos(840, -353)
        first = jpg.knob('first').getValue()
        last = jpg.knob('last').getValue()
        proxy = jpg.knob('file').getValue()
        r3d.knob('first').setValue(first)
        r3d.knob('origfirst').setValue(first)
        r3d.knob('last').setValue(last)
        r3d.knob('origlast').setValue(last)
        r3d.knob('proxy').setValue(proxy)

    nuke.toNode('AddTimeCode1').setXYpos(730, 135)
    nuke.toNode('ModifyMetaData1').setXYpos(730, 159)
    nuke.toNode('Reformat1').setXYpos(730, 183)
    nuke.toNode('Reformat2').setXYpos(840, 183)
    nuke.toNode('Write_preview').setXYpos(730, 217)
    nuke.toNode('Write_master').setXYpos(840, 217)

    nuke.toNode('AddTimeCode1').connectInput(0, nuke.toNode('HieroData'))

    viewer = None
    for n in nuke.allNodes():
        if n.Class() == 'Viewer':
            viewer = n
    if viewer == None:
        print "has no viewer"
        viewer = nuke.createNode("Viewer")
    viewer.setXYpos(730, 263)
    viewer.connectInput(0, nuke.toNode('Write_preview'))
    
    nuke.root().knob('proxy_type').setValue('scale')
    #nuke.scriptSaveAs(filepath.replace(".nk", "_test.nk"), 1)
    nuke.scriptSaveAs(filepath, 1)
    nuke.scriptExit()
Example #5
0
def cmdLaunch(XS):

    defineNuke = '"' + nuke.env["ExecutablePath"] + '"'
    if XS == 1:
        defineNuke += " --nukeassist"
    elif XS == 2:
        defineNuke += " --nukex"
    elif XS == 3:
        defineNuke += " --studio"
    else:
        pass

    if system() == 'Windows':
        startCommand = "start cmd /k "
    elif system() == 'Linux':
        startCommand = findTerminal() + " -e "

    cmdStart = startCommand + defineNuke
    popen(cmdStart)
    nuke.scriptExit()
def cmdExecute():
    Nwrite = nuke.selectedNode()
    NName = Nwrite['name'].value()
    fRange = nuke.activeViewer().node()['frame_range'].getValue()

    #Get list of available CPU threads
    actThd = multiprocessing.cpu_count()
    thds = ""
    thd = range(1, actThd + 1)
    for n in thd:
        thds += str(n) + " "

    #Check if selected node is executable
    if Nwrite.Class() not in [
            'Write', 'DeepWrite', 'WriteGeo', 'WriteTank', 'SmartVector'
    ]:
        nuke.message('Selected node is not executable via CMD!'
                     )  #making sure selected node is executable
    else:
        i = nuke.Panel('Render settings')
        i.addSingleLineInput('first', nuke.root().firstFrame())
        i.addSingleLineInput('last', nuke.root().lastFrame())
        i.addEnumerationPulldown('threads', thds)
        i.addBooleanCheckBox('Save new version', 0)
        i.addBooleanCheckBox('NukeX', 0)
        i.addBooleanCheckBox('Close Nuke', 0)
        if i.show():
            try:
                nuke.scriptSave("")
                ret = [int(i.value('first')), int(i.value('last'))]
                rThd = int(i.value('threads'))
                sav = i.value('Save new version')
                X = i.value('NukeX')
                nukeQuit = i.value('Close Nuke')

                if X == 1:
                    args = '"' + nuke.env["ExecutablePath"] + '"' + " --nukex" \
                       + " -i -m " + str(rThd) \
                       + " -X " + NName \
                       + " -F " + str(ret[0]) + '-' + str(ret[1]) \
                       + " " + '"' + nuke.scriptName() + '"' #Quote unquote for spaces in BAT
                else:
                    args = '"' + nuke.env["ExecutablePath"] + '"' \
                       + " -i -m " + str(rThd) \
                       + " -X " + NName \
                       + " -F " + str(ret[0]) + '-' + str(ret[1]) \
                       + " " + '"' + nuke.scriptName() + '"' #Quote unquote for spaces in BAT

                #identify OS
                if platform.system() == "Windows":
                    startCMD = "start cmd /k " + '"' + args + '"'  #Quote unquote in case both paths have spaces
                    print args
                if platform.system() == "Linux":
                    startCMD = "gnome-terminal -x " + args  #Quote unquote in case both paths have spaces
                os.popen(startCMD)

                #save new version
                if sav == 1:
                    nukescripts.script_and_write_nodes_version_up()

                #quit
                if nukeQuit == 1:
                    nuke.scriptExit()

            except:
                nuke.message('Invalid input')
Example #7
0
# if video is loaded.
startFrame = oRead['origfirst'].value()
endFrame = oRead['origlast'].value()

#find and get 1st view
view = (oWrite['views'].value() or '').split(' ')[:1]

nuke.execute(oWrite, int(startFrame), int(endFrame), views=view)

#oGrade.setInput(0, oRead)
#oColourSpace.setInput(0, oGrade)
oWrite.setInput(0, oRead)
#oWrite.setInput(0,oColourSpace)

nuke.scriptSaveAs(dShotInfo['FilePath'])
nuke.scriptExit()

sys.exit(0)  # Stops running from this point on.

##################
sScript = '/proj/uap/shots/0571gr/0140/motion/work/maya/dyabu/Images/PB/1/TEMP.nk'

inputSeq = '/proj/uap/shots/0571gr/0140/motion/work/maya/dyabu/Images/PB/3/PlayBlast_3.####.jpg'
outSeq = '/proj/uap/shots/0571gr/0140/motion/work/maya/dyabu/Images/PB/1/PlayBlast_1.####.jpg'
startFrame = 1009
endFrame = 1009
gamma = 1

sAll = '''
#import os
import re
Example #8
0
def quit_nuke(force=True):
    nuke.scriptExit(forceExit=force)
Example #9
0
def re_render_exr(folder_list, cur_folder):
	
	for folder in folder_list:

		#Go to next line in txt file if line contains a # (comment).
		if "#" in folder:
			continue
		
		#Return all folder files.
		files_list = os.listdir(folder)

		#Retrieve the number of frames.
		nbr_frame = len(os.listdir(folder))

		#Get the name of the first and last frame (in order to retrieve frame range).
		file_name_first = os.listdir(folder)[0]
		file_name_last = os.listdir(folder)[-1]

		#Get the padding of the first frame.
		padding = re.search("[0-9]{4}", file_name_first)
		padding = padding.group(0)

		#Get the padding of the last frame.
		padding_last = re.search("[0-9]{4}", file_name_last)
		padding_last = padding_last.group(0)
	
		#Convert the file_name from #### padding to %04d padding.
		file_name_first = file_name_first.replace(padding, "%0" + str(len(padding)) + "d")


		folder = folder.replace("\\", "/")

		nuke.scriptOpen(cur_folder + "\\exr_re_render.nk")

		#Retrieve Read and Write nodes.
		read_node = nuke.toNode("Read")
		write_node = nuke.toNode("Write")		

		#Change frame range.
		read_node.knob("first").setValue(int(padding))
		read_node.knob("last").setValue(int(padding_last))

		#Replace the read and write nodes paths.
		read_node.knob("file").setValue(folder + "/" + file_name_first)
		write_node.knob("file").setValue(folder + "/tmp/" + file_name_first)

		#Creates a tmp folder to write files to.
		os.makedirs(folder + "\\tmp")

		#Render all frames.
		nuke.execute ("Write",0,nbr_frame,1)

		#Exit Nuke.
		nuke.scriptExit()

		#Move all files from tmp to original folder.
		for i in files_list:
			os.remove(folder + "/" + i)

		for i in os.listdir(folder + "/tmp"):
			shutil.move(folder + "/tmp/" + i, folder)

		#Remove tmp folder.
		shutil.rmtree(folder + "/tmp", ignore_errors=True)