コード例 #1
0
def remove_preset():
    '''remove preset button'''

    node = nuke.thisNode()

    knob_presets = [
        str(k + ' | ' + node.knob(k).label()) for k in node.knobs()
        if k.startswith(PRESET_STR)
    ]

    p = nukescripts.PythonPanel('Remove A Preset')
    pk_knoblist = nuke.Enumeration_Knob('knoblist', "Delete Preset: ",
                                        knob_presets)
    p.addKnob(pk_knoblist)

    if p.showModalDialog():
        knob_delete = node.knob(pk_knoblist.value().split(' | ')[0])
        node.removeKnob(knob_delete)
コード例 #2
0
def FromNuke2MayaExporter():
	allSelectedNodes = nuke.selectedNodes()
	
	firstFrame = nuke.root().knob('first_frame').getValue()
	lastFrame = nuke.root().knob('last_frame').getValue()
	
	if len(allSelectedNodes) == 1:
		selectedNode = allSelectedNodes[0]
		selectedNodeType = selectedNode.Class()
		
		channelMatch = {'transform.tx':'translate:0', 'transform.ty':'translate:1', 'transform.tz':'translate:2', 'transform.rx':'rotate:0', 'transform.ry':'rotate:1', 'transform.rz':'rotate:2', 'transform.sx':'scaling:0', 'transform.sy':'scaling:1', 'transform.sz':'scaling:2', 'transform.rotateOrder':'rot_order', 'camera.fl':'focal', 'camera.horizontalFilmAperture':'haperture', 'camera.verticalFilmAperture':'vaperture'}
		objectTypeOk = ['Camera', 'Camera2']
		
		cameraName = selectedNode.name()
		
		if selectedNodeType in objectTypeOk:
			
			exportPath = os.environ["HOME"].replace('\\', '/') + '/Desktop/'
			
			a = nukescripts.PythonPanel('File to Export')
			a.addKnob(nuke.Int_Knob('Start-Frame:'))
			a.knobs()['Start-Frame:'].setValue(int(firstFrame))
			a.addKnob(nuke.Int_Knob('End-Frame:'))
			a.knobs()['End-Frame:'].setValue(int(lastFrame))
			a.addKnob(nuke.File_Knob('Export-File:'))
			a.knobs()['Export-File:'].setValue(exportPath+cameraName + '.fm2n')
			finishedDialog = a.showModalDialog()
			
			startFrame = int(a.knobs()['Start-Frame:'].getValue())
			lastFrame = int(a.knobs()['End-Frame:'].getValue())
			filename = a.knobs()['Export-File:'].getValue()
			
			filename = filename.replace('\\', '/')
			
			filenameParts = filename.split('.')
			if filenameParts[len(filenameParts)-1] != 'fm2n':
				filename = filename + ".fm2n"
			
			exportData(selectedNode, channelMatch, firstFrame, lastFrame, filename)	
		else:
			nuke.message("ERROR: The Node you have selected is not a Camera.")
	
	else:
		nuke.message("ERROR: You have more then one Node selected")
コード例 #3
0
ファイル: archive.py プロジェクト: storm201001/vfxpipe
 def interface(self):
     # set up the new script name
     scriptName = os.path.basename(nuke.value('root.name'))
     date = datetime.date.today()
     formattedDate = '%s%02d%02d' % (date.year, int(date.month), int(date.day))
     archivePath = 'z:/job/after_earth/prod/io/archive/%s/%s/' % (formattedDate, scriptName.replace('.nk',''))
     self.panel = nukescripts.PythonPanel('Archive script 1.01')
     self.file = nuke.File_Knob('Output','Output folder:')
     self.file.setValue(archivePath)
     self.panel.addKnob(self.file)
     self.scriptName = nuke.String_Knob('name','Script name:',scriptName)
     self.panel.addKnob(self.scriptName)
     self.log = nuke.Boolean_Knob('log','Generate log:',True)
     self.panel.addKnob(self.log)
     self.comment = nuke.Multiline_Eval_String_Knob('comment','Comments:')
     self.panel.addKnob(self.comment)
     result = self.panel.showModalDialog()
     self.scriptInfo = nukescripts.get_script_data()
     if result:
         self.convertGizmosToGroups()
         self.action()
コード例 #4
0
def bm_QuickKeys(type):

    # Set some initial variables for later use.
    node = nuke.selectedNode()
    frame = nuke.frame()

    # Find the correct knob based on the node's class. If it's not specified, presume the user
    # wants to use the shortcut on the mix knob.
    dict = {
        'Switch': 'which',
        'Dissolve': 'which',
        'Roto': 'opacity',
        'RotoPaint': 'opacity'
    }

    if node.Class() in dict.keys():
        knob = node.knob(dict[node.Class()])
    else:
        knob = node.knob('mix')

    # If the mix knob has a non-zero value we should use it, but if it's zero things can break so we'll use 1 instead.
    if knob.value() != 0:
        knob_value = knob.value()
    else:
        knob_value = 1

    # Now, let's make things work!

    # "on" is the function's argument. We're using it as an easy way to set shortcuts,
    # But there is no error-checking because users won't be seeing / setting them.

    # "on" sets a keyframe with the current value on the current frame, and a keyframe with a value of 0 on the previous frame.
    if type == "on":

        # Prime node for animation
        knob.setAnimated(0)
        knob_anim = knob.animations()[0]

        knob_anim.setKey(frame, knob_value)
        knob_anim.setKey(frame - 1, 0)
        return

    # "off" sets a keyframe with the current value on the current frame, and a keyframe with a value of 0 on the next frame.
    elif type == "off":

        # Prime node for animation
        knob.setAnimated(0)
        knob_anim = knob.animations()[0]

        knob_anim.setKey(frame, knob_value)
        knob_anim.setKey(frame + 1, 0)
        return

    # "offonoff" sets a keyframe with the current value on the current frame, and a keyframe with a value of 0 on both the next and the previous frames.
    elif type == "offonoff":

        # Prime node for animation
        knob.setAnimated(0)
        knob_anim = knob.animations()[0]

        knob_anim.setKey(frame - 1, 0)
        knob_anim.setKey(frame, knob_value)
        knob_anim.setKey(frame + 1, 0)
        return

    # "onoffon" sets a keyframe with a value of 0 on the current frame, and a keyframe with the current value on both the next and the previous frames.
    elif type == "onoffon":

        # Prime node for animation
        knob.setAnimated(0)
        knob_anim = knob.animations()[0]

        knob_anim.setKey(frame - 1, knob_value)
        knob_anim.setKey(frame, 0)
        knob_anim.setKey(frame + 1, knob_value)
        return

    # "custom" is a little more involved, as it opens a panel. You can set whatever values you want, including a "fade" option to make transitions
    # not-so-instant.
    elif type == "custom":

        # Create the panel
        panel = nukescripts.PythonPanel("Quick Keys")

        # Add the knobs, position them on the pop-up window and set default values
        on_frame_input = nuke.Int_Knob('on_frame_input', 'First Frame')
        on_frame_input.setValue(frame)
        panel.addKnob(on_frame_input)

        on_frame_value = nuke.Double_Knob('on_frame_value', '   Set value')
        on_frame_value.setValue(knob_value)
        on_frame_value.clearFlag(nuke.STARTLINE)
        panel.addKnob(on_frame_value)

        on_chk = nuke.Boolean_Knob('on_chk', 'enable', True)
        panel.addKnob(on_chk)

        off_frame_input = nuke.Int_Knob('off_frame_input', 'Last Frame')
        off_frame_input.setValue(frame + 10)
        panel.addKnob(off_frame_input)

        off_frame_value = nuke.Double_Knob('off_frame_value', '   Set value')
        off_frame_value.setValue(knob_value)
        off_frame_value.clearFlag(nuke.STARTLINE)
        panel.addKnob(off_frame_value)

        off_chk = nuke.Boolean_Knob('off_chk', 'enable', True)
        panel.addKnob(off_chk)

        fade_input = nuke.Int_Knob('fade_frame_input', 'Fade Duration', frame)
        panel.addKnob(fade_input)

        fade_chk = nuke.Boolean_Knob('fade_chk', 'enable', True)
        panel.addKnob(fade_chk)

        # If the window successfully opens and the ok button is pressed, do the things.
        if panel.showModalDialog() == True:

            # Prime node for animation
            knob.setAnimated(0)
            knob_anim = knob.animations()[0]

            # If there's no fading happening, we need to force an offset of 1 frame so keyframes don't overwrite each other.
            if fade_chk.value() == False or fade_input.value() == 0:
                fade_input.setValue(1)

            if on_chk.value() == True:
                knob_anim.setKey(on_frame_input.value(),
                                 on_frame_value.value())
                knob_anim.setKey(on_frame_input.value() - (fade_input.value()),
                                 0)

            if off_chk.value() == True:
                knob_anim.setKey(off_frame_input.value(),
                                 off_frame_value.value())
                knob_anim.setKey(
                    off_frame_input.value() + (fade_input.value()), 0)

        # Otherwise, if the cancel button is pressed, don't do anything...
        else:
            return
コード例 #5
0
def FromMaya2NukeImporter():
    importFile = True
    allSelectedNodes = nuke.selectedNodes()

    if len(allSelectedNodes) > 1:
        nuke.message("ERROR: You have more then one Node selected")
    else:
        a = nukescripts.PythonPanel('Choose File to import')
        a.addKnob(nuke.File_Knob('Import-File:'))
        finishedDialog = a.showModalDialog()

        if finishedDialog == True:
            filename = a.knobs()['Import-File:'].getValue()

            filenameParts = filename.split('.')
            if filenameParts[len(filenameParts) - 1] != 'fm2n':
                nuke.message(
                    "ERROR: You have not selected a 'fm2n'-File. Please select a valid File!'"
                )
                importFile = False

            file = open(filename, 'r')
            line = file.readline()
            file.close()

            values = line.split('\t')

            objectName = values[0]
            objectNodeType = values[1]

            lightTypes = ['point', 'spot', 'directional']

            if objectNodeType == 'camera':
                channelMatch = {
                    'transform.tx': 'translate:0',
                    'transform.ty': 'translate:1',
                    'transform.tz': 'translate:2',
                    'transform.rx': 'rotate:0',
                    'transform.ry': 'rotate:1',
                    'transform.rz': 'rotate:2',
                    'transform.sx': 'scaling:0',
                    'transform.sy': 'scaling:1',
                    'transform.sz': 'scaling:2',
                    'transform.rotateOrder': 'rot_order',
                    'camera.fl': 'focal',
                    'camera.horizontalFilmAperture': 'haperture',
                    'camera.verticalFilmAperture': 'vaperture'
                }
            elif objectNodeType == 'locator':
                channelMatch = {
                    'transform.tx': 'translate:0',
                    'transform.ty': 'translate:1',
                    'transform.tz': 'translate:2',
                    'transform.rx': 'rotate:0',
                    'transform.ry': 'rotate:1',
                    'transform.rz': 'rotate:2',
                    'transform.sx': 'scaling:0',
                    'transform.sy': 'scaling:1',
                    'transform.sz': 'scaling:2',
                    'transform.rotateOrder': 'rot_order'
                }
            elif objectNodeType in lightTypes:
                channelMatch = {
                    'transform.tx': 'translate:0',
                    'transform.ty': 'translate:1',
                    'transform.tz': 'translate:2',
                    'transform.rx': 'rotate:0',
                    'transform.ry': 'rotate:1',
                    'transform.rz': 'rotate:2',
                    'transform.sx': 'scaling:0',
                    'transform.sy': 'scaling:1',
                    'transform.sz': 'scaling:2',
                    'transform.rotateOrder': 'rot_order',
                    'transform.intensity': 'intensity',
                    'transform.cr': 'color:0',
                    'transform.cg': 'color:1',
                    'transform.cb': 'color:2',
                    'transform.coneAngle': 'cone_angle',
                    'transform.penumbraAngle': 'cone_penumbra_angle',
                    'transform.dropoff': 'cone_falloff'
                }
            else:
                nuke.message(
                    "ERROR: The Object-Type is not supported. Please make sure that you have selected the right File and it contains either Camera- or Light-Data!"
                )
                importFile = False

            if len(allSelectedNodes) == 1:
                objectName = allSelectedNodes[0].knob('name').value()
                objectTypeGoal = allSelectedNodes[0].Class()

                thisNode = allSelectedNodes[0]

                if objectNodeType == 'spot':
                    objectTypeOk = ['Spotlight', 'Light2']
                elif objectNodeType == 'point':
                    objectTypeOk = ['Light', 'Light2']
                elif objectNodeType == 'directional':
                    objectTypeOk = ['DirectLight', 'Light2']
                elif objectNodeType == 'camera':
                    objectTypeOk = ['Camera', 'Camera2']
                elif objectNodeType == 'locator':
                    objectTypeOk = [
                        'Axis', 'Axis2', 'TransformGeo', 'Card', 'Card2',
                        'Cube', 'Cylinder', 'Sphere', 'ReadGeo', 'ReadGeo2',
                        'Light', 'Light2', 'Spotlight', 'DirectLight',
                        'Camera', 'Camera2'
                    ]

                if objectTypeGoal not in objectTypeOk:
                    nuke.message("ERROR: The File contains data for a " +
                                 objectNodeType + " but there is a " +
                                 objectTypeGoal +
                                 " selected. Please select the right node!")
                    importFile = False

            else:
                if objectNodeType == 'camera':
                    thisNode = nuke.nodes.Camera(name=objectName)
                elif objectNodeType == 'locator':
                    thisNode = nuke.nodes.Axis2(name=objectName)
                else:
                    thisNode = nuke.nodes.Light2(name=objectName)

            if importFile == True:
                importData(filename, channelMatch, thisNode)