Ejemplo n.º 1
0
    def swapOutNode(self, targetNode, newNode):
        '''
        Mostly mimics the Ctrl + Shift + drag-and-drop node functionality in Nuke.

        'targetNode': The node (or node name) to be replaced.
        'newNode': The node (or node name) that will replace it.
        '''
        if isinstance(targetNode, basestring):
            targetNode = nuke.toNode(targetNode)
        if isinstance(newNode, basestring):
            newNode = nuke.toNode(newNode)
        if not (isinstance(targetNode, nuke.Node) and isinstance(newNode, nuke.Node)):
            return
        sourcePos = (newNode.xpos(), newNode.ypos())
        targetPos = (targetNode.xpos(), targetNode.ypos())
        oldSel = nuke.selectedNodes()
        inputNodes, outputNodes = self.getConnectedNodes(targetNode)
        nukescripts.clear_selection_recursive()
        targetNode.setSelected(True)
        nuke.extractSelected()
        targetNode.setSelected(False)
        newNode.setXYpos(*targetPos)
        targetNode.setXYpos(*sourcePos)
        for inNode in inputNodes:
            newNode.setInput(*inNode)
        for index, node in outputNodes:
            node.setInput(index, newNode)
        for node in oldSel:
            node.setSelected(True)
        return True
Ejemplo n.º 2
0
def pv2_createGizmo(nuke):
 	#create 2 scene nodes and select
	epScene = nuke.createNode("Scene")
	epScene.setName("Emitters")
	epScene.setXpos(0)
	epScene.setYpos(-100)

	#now create gizmo to have it auto connect
	nuke.nodePaste("~/.nuke/Particular3DGroup.nk")
	nuke.extractSelected()
	gizmo = nuke.selectedNode()
	gizmo.setXpos(0)
	gizmo.setYpos(0)
	gizmo.setInput(1,epScene)
	nuke.show(gizmo)
	
	#add version check
	if nuke.NUKE_VERSION_MINOR < 1 :
		#change cam values to work with translate values only
		gizmoParticularPath = "%s.Particular v2_1" % gizmo.name()
		camExpressionX = "p_cam.translate.x * parent.pv2_camXMultiplier"
		camExpressionY = "p_cam.translate.y * parent.pv2_camYMultiplier"
		camExpressionZ = "p_cam.translate.z"
		
		print "Camera cannot be parented to Axis node"
		nuke.toNode(gizmoParticularPath)['CameraPos'].setExpression(camExpressionX, 0)
		nuke.toNode(gizmoParticularPath)['CameraPos'].setExpression(camExpressionY, 1)	
		nuke.toNode(gizmoParticularPath)['CameraPos'].setExpression(camExpressionZ, 2)			
Ejemplo n.º 3
0
def pv2_createGizmo(nuke):
 	#create 2 scene nodes and select
	epScene = nuke.createNode("Scene")
	epScene.setName("Emitters")
	epScene.setXpos(0)
	epScene.setYpos(-100)

	#now create gizmo to have it auto connect
	nuke.nodePaste("~/.nuke/Particular3DGroup.nk")
	nuke.extractSelected()
	gizmo = nuke.selectedNode()
	gizmo.setXpos(0)
	gizmo.setYpos(0)
	gizmo.setInput(1,epScene)
	nuke.show(gizmo)
	
	#add version check
	if nuke.NUKE_VERSION_MINOR < 1 :
		#change cam values to work with translate values only
		gizmoParticularPath = "%s.Particular v2_1" % gizmo.name()
		camExpressionX = "p_cam.translate.x * parent.pv2_camXMultiplier"
		camExpressionY = "p_cam.translate.y * parent.pv2_camYMultiplier"
		camExpressionZ = "p_cam.translate.z"
		
		print "Camera cannot be parented to Axis node"
		nuke.toNode(gizmoParticularPath)['CameraPos'].setExpression(camExpressionX, 0)
		nuke.toNode(gizmoParticularPath)['CameraPos'].setExpression(camExpressionY, 1)	
		nuke.toNode(gizmoParticularPath)['CameraPos'].setExpression(camExpressionZ, 2)			
Ejemplo n.º 4
0
def disconnectViewers():
    nuke.selectAll()
    nuke.invertSelection()

    for n in nuke.allNodes():
        if n.Class() == "Viewer":
            n['selected'].setValue(True)

    nuke.extractSelected()
Ejemplo n.º 5
0
def disconnect():
    import nuke
    n = nuke.allNodes('Viewer')
    for v in n:
        v.setSelected(True)
        x = v['xpos'].value()
        y = v['ypos'].value()
        nuke.extractSelected()
        v.setXYpos(x, y)
        v.setSelected(False)
Ejemplo n.º 6
0
def FootageConverter():
	imageWidth = 0
	imageHeight = 0

	for n in nuke.allNodes():
		if n.Class() == "Read":
			imageWidth = n.width()
			imageHeight = n.height()

	class dialog ( object ):
		window = nuke.Panel("Footage Converter")
		window.addEnumerationPulldown("File Format:", "exr jpeg png tiff")
		window.addEnumerationPulldown("Render to:", "SameFolder CreateSubfolder")
		window.addBooleanCheckBox("Reformat?", "0 1")
		window.addSingleLineInput("Image Width:", imageWidth)
		window.addSingleLineInput("Image Height:", imageHeight)
		window.addSingleLineInput("Divide by:", 1)
		window.addSingleLineInput("Percent:", 100)
		window.addEnumerationPulldown("Reformat Filter:", "Cubic Impulse Keys Simon Rifman Mitchell Parzen Notch")
		window.addBooleanCheckBox("Selected Nodes Only", "0 1")
		
	dialogResult = dialog.window.show()
	
	if dialogResult == 1:
		nuke.tprint("Running FootageConvert Script")
	else:
		nuke.tprint("Canceled")
		return None

	if dialog.window.value("Reformat?") == 1:
		
		if imageWidth == dialog.window.value("Image Width:") or imageHeight == dialog.window.value("Image Height:"):
			nuke.tprint("")
		else:
			newWidth = dialog.window.value("Image Width:")
			newHeight = dialog.window.value("Image Height:")
			
		if dialog.window.value("Divide by:") == "1":
			nuke.tprint("")
		else:
			newWidth = int(imageWidth / int(dialog.window.value("Divide by:")))
			newHeight = int(imageHeight / int(dialog.window.value("Divide by:")))
			
		if dialog.window.value("Percent:") == "100":
			nuke.tprint("")
		else:
			newWidth = int(imageWidth * int(dialog.window.value("Percent:")) / 100)
			newHeight = int(imageHeight * int(dialog.window.value("Percent:")) / 100)

	class exr ( object ):
		window = nuke.Panel("EXR Options")
		window.addEnumerationPulldown("Data Type:", "16_Bit_Half 32_Bit_Float")
		window.addEnumerationPulldown("Compression:", "Zip_1_Scanline Zip_16_Scanlines PIZ_Wavelet_32_Scanlines RLE B44 None")
		
	class jpeg ( object ):
		window = nuke.Panel("JPEG Options")
		window.addSingleLineInput("Quality:", 100)
		
	class png ( object ):
		window = nuke.Panel("PNG Options")
		window.addEnumerationPulldown("Data Type:", "8_Bit 16_Bit")
		
	class tiff ( object ):
		window = nuke.Panel("TIFF Options")
		window.addEnumerationPulldown("Data Type:", "8_Bit 16_Bit 32_Bit_Float")
		window.addEnumerationPulldown("Compression:", "Deflate LZW PackBits None")
		
	if dialog.window.value("File Format:") == "exr":
		formatResult = exr.window.show()
		
	if dialog.window.value("File Format:") == "jpeg":
		formatResult = jpeg.window.show()
		
	if dialog.window.value("File Format:") == "png":
		formatResult = png.window.show()
		
	if dialog.window.value("File Format:") == "tiff":
		formatResult = tiff.window.show()
		
	if formatResult == 1:
		nuke.tprint("")
	else:
		nuke.tprint("Canceled")
		return None
		
	if dialog.window.value("Selected Nodes Only") == 1:
		for n in nuke.selectedNodes():
			if n.Class() == "Read":
				nodeYPos = n.ypos()
				nodeXPos = n.xpos()
				
				readFile = n.knob('file').getValue()
				
				tempPath = readFile.split('/')
				newPath = ""
				
				for i in range(0, len(tempPath) - 1):
					newPath += tempPath[i] + "/"
					
				if dialog.window.value("Render to:") == "SameFolder":
					newPath = newPath
					if dialog.window.value("Reformat?") == 1:
						newPath += "_reformat/"
						try:
							os.mkdir(newPath)
						except:
							nuke.tprint("Render Folder already exists!")
				else:
					newPath += "_%s/" % (dialog.window.value("File Format:"))
					try:
						os.mkdir(newPath)
					except:
						nuke.tprint("Render Folder already exists!")
					
				fileName = readFile.split('/')[ - 1]
				fileNameTable = fileName.split('.')
				newFileName = ""
				
				for i in range(0, len(fileNameTable) -1):
					newFileName += fileNameTable[i] + "."
					
				newPath += newFileName
				
				if dialog.window.value("File Format:") == "exr":
					newPath += "exr"
				if dialog.window.value("File Format:") == "jpeg":
					newPath += "jpg"
				if dialog.window.value("File Format:") == "png":
					newPath += "png"
				if dialog.window.value("File Format:") == "tiff":
					newPath += "tif"
				
				if dialog.window.value("Reformat?") == 1:
					reformat = nuke.createNode("Reformat")
					nuke.extractSelected()
					reformat.knob('xpos').setValue(nodeXPos)
					reformat.knob('ypos').setValue(nodeYPos + 150)
					reformat.knob('filter').setValue(dialog.window.value("Reformat Filter:"))
					
					print newWidth
					print newHeight
					
					reformat.knob('type').setValue("to box")
					reformat.knob('box_fixed').setValue(1)
					reformat.knob('box_width').setValue(int(newWidth))
					reformat.knob('box_height').setValue(int(newHeight))
					
					write = nuke.createNode("Write")
					nuke.extractSelected()
					write.knob('xpos').setValue(nodeXPos)
					write.knob('ypos').setValue(nodeYPos + 300)
					
					reformat.setInput(0, n)
					write.setInput(0, reformat)
				else:
					write = nuke.createNode("Write")
					nuke.extractSelected()
					write.knob('xpos').setValue(nodeXPos)
					write.knob('ypos').setValue(nodeYPos + 150)
					
					write.setInput(0, n)
					
				write.knob('file').setValue(newPath)
				write.knob('file_type').setValue(dialog.window.value("File Format:"))
				
				if dialog.window.value("File Format:") == "exr":
					if exr.window.value("Data Type:") == "16_Bit_Half":
						write.knob('datatype').setValue("16 bit half")
					if exr.window.value("Data Type:") == "32_Bit_Float":
						write.knob('datatype').setValue("32 bit float")
					
					if exr.window.value("Compression:") == "Zip_1_Scanline":
						write.knob('compression').setValue("Zip (1 scanline)")
					if exr.window.value("Compression:") == "Zip_16_Scanlines":
						write.knob('compression').setValue("Zip (16 scanlines)")
					if exr.window.value("Compression:") == "PIZ_Wavelet_32_Scanlines":
						write.knob('compression').setValue("PIZ Wavelet (32 scanlines)")
					if exr.window.value("Compression:") == "RLE":
						write.knob('compression').setValue("RLE")
					if exr.window.value("Compression:") == "B44":
						write.knob('compression').setValue("B44")
					if exr.window.value("Compression:") == "None":
						write.knob('compression').setValue("none")
					
				if dialog.window.value("File Format:") == "jpeg":
					write.knob('_jpeg_quality').setValue(float(jpeg.window.value("Quality:")) / 100)
					
				if dialog.window.value("File Format:") == "png":
					if png.window.value("Data Type:") == "8_Bit":
						write.knob('datatype').setValue("8 bit")
					if png.window.value("Data_Type:") == "16_Bit":
						write.knob('datatype').setValue("16 bit")
					
				if dialog.window.value("File Format:") == "tiff":
					if tiff.window.value("Data Type:") == "8_Bit":
						write.knob('datatype').setValue("8 bit")
					if tiff.window.value("Data Type:") == "16_Bit":
						write.knob('datatype').setValue("16 bit")
					if tiff.window.value("Data Type:") == "32_Bit_Float":
						write.knob('datatype').setValue("32 bit float")
						
					if tiff.window.value("Compression:") == "Deflate":
						write.knob('compression').setValue("Deflate")
					if tiff.window.value("Compression:") == "LZW":
						write.knob('compression').setValue("LZW")
					if tiff.window.value("Compression:") == "PackBits":
						write.knob('compression').setValue("PackBits")
					if tiff.window.value("Compression:") == "None":
						write.knob('compression').setValue("none")
						
				n.knob('proxy').setValue(newPath)
	else:
		for n in nuke.allNodes():
			if n.Class() == "Read":
				nodeYPos = n.ypos()
				nodeXPos = n.xpos()
				
				readFile = n.knob('file').getValue()
				
				tempPath = readFile.split('/')
				newPath = ""
				
				for i in range(0, len(tempPath) - 1):
					newPath += tempPath[i] + "/"
					
				if dialog.window.value("Render to:") == "SameFolder":
					newPath = newPath
				else:
					newPath += "_%s/" % (dialog.window.value("File Format:"))
					try:
						os.mkdir(newPath)
					except:
						nuke.tprint("Render Folder already exists!")
					
				fileName = readFile.split('/')[ - 1]
				fileNameTable = fileName.split('.')
				newFileName = ""
				
				for i in range(0, len(fileNameTable) -1):
					newFileName += fileNameTable[i] + "."
					
				newPath += newFileName
				
				if dialog.window.value("File Format:") == "exr":
					newPath += "exr"
				if dialog.window.value("File Format:") == "jpeg":
					newPath += "jpg"
				if dialog.window.value("File Format:") == "png":
					newPath += "png"
				if dialog.window.value("File Format:") == "tiff":
					newPath += "tif"
				
				if dialog.window.value("Reformat?") == 1:
					reformat = nuke.createNode("Reformat")
					nuke.extractSelected()
					reformat.knob('xpos').setValue(nodeXPos)
					reformat.knob('ypos').setValue(nodeYPos + 150)
					reformat.knob('filter').setValue(dialog.window.value("Reformat Filter:"))
					
					print newWidth
					print newHeight
					
					reformat.knob('type').setValue("to box")
					reformat.knob('box_fixed').setValue(1)
					reformat.knob('box_width').setValue(int(newWidth))
					reformat.knob('box_height').setValue(int(newHeight))
					
					write = nuke.createNode("Write")
					nuke.extractSelected()
					write.knob('xpos').setValue(nodeXPos)
					write.knob('ypos').setValue(nodeYPos + 300)
					
					reformat.setInput(0, n)
					write.setInput(0, reformat)
				else:
					write = nuke.createNode("Write")
					nuke.extractSelected()
					write.knob('xpos').setValue(nodeXPos)
					write.knob('ypos').setValue(nodeYPos + 150)
					
					write.setInput(0, n)
					
				write.knob('file').setValue(newPath)
				write.knob('file_type').setValue(dialog.window.value("File Format:"))
				
				if dialog.window.value("File Format:") == "exr":
					if exr.window.value("Data Type:") == "16_Bit_Half":
						write.knob('datatype').setValue("16 bit half")
					if exr.window.value("Data Type:") == "32_Bit_Float":
						write.knob('datatype').setValue("32 bit float")
					
					if exr.window.value("Compression:") == "Zip_1_Scanline":
						write.knob('compression').setValue("Zip (1 scanline)")
					if exr.window.value("Compression:") == "Zip_16_Scanlines":
						write.knob('compression').setValue("Zip (16 scanlines)")
					if exr.window.value("Compression:") == "PIZ_Wavelet_32_Scanlines":
						write.knob('compression').setValue("PIZ Wavelet (32 scanlines)")
					if exr.window.value("Compression:") == "RLE":
						write.knob('compression').setValue("RLE")
					if exr.window.value("Compression:") == "B44":
						write.knob('compression').setValue("B44")
					if exr.window.value("Compression:") == "None":
						write.knob('compression').setValue("none")
					
				if dialog.window.value("File Format:") == "jpeg":
					write.knob('_jpeg_quality').setValue(float(jpeg.window.value("Quality:")) / 100)
					
				if dialog.window.value("File Format:") == "png":
					if png.window.value("Data Type:") == "8_Bit":
						write.knob('datatype').setValue("8 bit")
					if png.window.value("Data_Type:") == "16_Bit":
						write.knob('datatype').setValue("16 bit")
					
				if dialog.window.value("File Format:") == "tiff":
					if tiff.window.value("Data Type:") == "8_Bit":
						write.knob('datatype').setValue("8 bit")
					if tiff.window.value("Data Type:") == "16_Bit":
						write.knob('datatype').setValue("16 bit")
					if tiff.window.value("Data Type:") == "32_Bit_Float":
						write.knob('datatype').setValue("32 bit float")
						
					if tiff.window.value("Compression:") == "Deflate":
						write.knob('compression').setValue("Deflate")
					if tiff.window.value("Compression:") == "LZW":
						write.knob('compression').setValue("LZW")
					if tiff.window.value("Compression:") == "PackBits":
						write.knob('compression').setValue("PackBits")
					if tiff.window.value("Compression:") == "None":
						write.knob('compression').setValue("none")
						
				n.knob('proxy').setValue(newPath)
Ejemplo n.º 7
0
def extract():
    """Disconnect all arrows between selected and unselected nodes, and move selected nodes to the right.
  This function is maintained only for compatibility.  Please use nuke.extractSelected() instead."""
    nuke.extractSelected()
Ejemplo n.º 8
0
def DuplicateGeometry():
    for n in nuke.selectedNodes():
        if n.Class() == "Cube" or n.Class() == "Card2" or n.Class(
        ) == "Cylinder" or n.Class() == "Sphere" or n.Class() == "ReadGeo2":

            class dialog(object):
                window = nuke.Panel("Duplicate Geometry")
                window.addSingleLineInput("Clones:", 10)

            dialogResult = dialog.window.show()

            if dialogResult == 1:
                nuke.tprint("Duplicating Geometry...")
            else:
                nuke.tprint("Canceled")
                return None

            nodeYPos = n.ypos()
            nodeXPos = n.xpos()

            controlNode = nuke.createNode("NoOp")
            controlNode.knob("name").setValue("DuplicateGeometry")
            controlNode.knob('xpos').setValue(nodeXPos + 150)
            controlNode.knob('ypos').setValue(nodeYPos)

            controlNode.addKnob(nuke.Tab_Knob('Controls'))

            code = 'import random\nfor a in range(%s):\n a += 1\n TKnob = \"Translate_\" + str(a)\n RKnob = \"Rotate_\" + str(a)\n SKnob = \"Scale_\" + str(a)\n nuke.toNode(\"DuplicateGeometry\").knob(TKnob).setValue(random.uniform(-1, 1), 0)\n nuke.toNode(\"DuplicateGeometry\").knob(TKnob).setValue(random.uniform(-1, 1), 1)\n nuke.toNode(\"DuplicateGeometry\").knob(TKnob).setValue(random.uniform(-1, 1), 2)\n nuke.toNode(\"DuplicateGeometry\").knob(RKnob).setValue(random.uniform(-1, 1), 0)\n nuke.toNode(\"DuplicateGeometry\").knob(RKnob).setValue(random.uniform(-1, 1), 1)\n nuke.toNode(\"DuplicateGeometry\").knob(RKnob).setValue(random.uniform(-1, 1), 2)\n nuke.toNode(\"DuplicateGeometry\").knob(SKnob).setValue(random.uniform(-1, 1), 0)\n nuke.toNode(\"DuplicateGeometry\").knob(SKnob).setValue(random.uniform(-1, 1), 1)\n nuke.toNode(\"DuplicateGeometry\").knob(SKnob).setValue(random.uniform(-1, 1), 2)' % int(
                dialog.window.value("Clones:"))

            controlNode.addKnob(
                nuke.PyScript_Knob('Randomize', 'Randomize', code))

            controlNode.addKnob(nuke.XYZ_Knob('Translate'))
            controlNode.addKnob(nuke.XYZ_Knob('Rotate'))
            controlNode.addKnob(nuke.XYZ_Knob('Scale'))

            controlNode.addKnob(nuke.XYZ_Knob('TranslateRandom'))
            controlNode.addKnob(nuke.XYZ_Knob('RotateRandom'))
            controlNode.addKnob(nuke.XYZ_Knob('ScaleRandom'))

            for a in range(int(dialog.window.value("Clones:"))):
                a += 1
                TKnob = "Translate_" + str(a)
                RKnob = "Rotate_" + str(a)
                SKnob = "Scale_" + str(a)
                controlNode.addKnob(nuke.XYZ_Knob(TKnob))
                controlNode.addKnob(nuke.XYZ_Knob(RKnob))
                controlNode.addKnob(nuke.XYZ_Knob(SKnob))

                controlNode.knob(TKnob).setVisible(bool(0))
                controlNode.knob(RKnob).setVisible(bool(0))
                controlNode.knob(SKnob).setVisible(bool(0))

                controlNode.knob(TKnob).setValue(random.uniform(-1, 1), 0)
                controlNode.knob(TKnob).setValue(random.uniform(-1, 1), 1)
                controlNode.knob(TKnob).setValue(random.uniform(-1, 1), 2)
                controlNode.knob(RKnob).setValue(random.uniform(-1, 1), 0)
                controlNode.knob(RKnob).setValue(random.uniform(-1, 1), 1)
                controlNode.knob(RKnob).setValue(random.uniform(-1, 1), 2)
                controlNode.knob(SKnob).setValue(random.uniform(-1, 1), 0)
                controlNode.knob(SKnob).setValue(random.uniform(-1, 1), 1)
                controlNode.knob(SKnob).setValue(random.uniform(-1, 1), 2)

            scene = nuke.createNode("Scene")
            scene.knob('xpos').setValue(nodeXPos + 300)
            scene.knob('ypos').setValue(nodeYPos + 150)
            nuke.extractSelected()

            for i in range(int(dialog.window.value("Clones:"))):
                transform = nuke.createNode("TransformGeo")
                nuke.extractSelected()
                transform.knob('xpos').setValue(nodeXPos + 150)
                transform.knob('ypos').setValue(nodeYPos + (150 * (i + 1)))
                transform.setInput(0, n)

                scene.setInput(i, transform)

                vTranslate_0 = "DuplicateGeometry.Translate * " + str(
                    i + 1
                ) + " + DuplicateGeometry.TranslateRandom * DuplicateGeometry.Translate_" + str(
                    i + 1)
                vTranslate_1 = "DuplicateGeometry.Translate * " + str(
                    i + 1
                ) + " + DuplicateGeometry.TranslateRandom * DuplicateGeometry.Translate_" + str(
                    i + 1)
                vTranslate_2 = "DuplicateGeometry.Translate * " + str(
                    i + 1
                ) + " + DuplicateGeometry.TranslateRandom * DuplicateGeometry.Translate_" + str(
                    i + 1)
                vRotate_0 = "DuplicateGeometry.Rotate * " + str(
                    i + 1
                ) + " + DuplicateGeometry.RotateRandom * DuplicateGeometry.Rotate_" + str(
                    i + 1)
                vRotate_1 = "DuplicateGeometry.Rotate * " + str(
                    i + 1
                ) + " + DuplicateGeometry.RotateRandom * DuplicateGeometry.Rotate_" + str(
                    i + 1)
                vRotate_2 = "DuplicateGeometry.Rotate * " + str(
                    i + 1
                ) + " + DuplicateGeometry.RotateRandom * DuplicateGeometry.Rotate_" + str(
                    i + 1)
                vScale_0 = "1 + DuplicateGeometry.Scale * " + str(
                    i + 1
                ) + " + DuplicateGeometry.ScaleRandom * DuplicateGeometry.Scale_" + str(
                    i + 1)
                vScale_1 = "1 + DuplicateGeometry.Scale * " + str(
                    i + 1
                ) + " + DuplicateGeometry.ScaleRandom * DuplicateGeometry.Scale_" + str(
                    i + 1)
                vScale_2 = "1 + DuplicateGeometry.Scale * " + str(
                    i + 1
                ) + " + DuplicateGeometry.ScaleRandom * DuplicateGeometry.Scale_" + str(
                    i + 1)

                transform.knob("translate").setExpression(vTranslate_0, 0)
                transform.knob("translate").setExpression(vTranslate_1, 1)
                transform.knob("translate").setExpression(vTranslate_2, 2)
                transform.knob("rotate").setExpression(vRotate_0, 0)
                transform.knob("rotate").setExpression(vRotate_1, 1)
                transform.knob("rotate").setExpression(vRotate_2, 2)
                transform.knob("scaling").setExpression(vScale_0, 0)
                transform.knob("scaling").setExpression(vScale_1, 1)
                transform.knob("scaling").setExpression(vScale_2, 2)
Ejemplo n.º 9
0
def DuplicateGeometry():
	for n in nuke.selectedNodes():
		if n.Class() == "Cube" or n.Class() == "Card2" or n.Class() == "Cylinder" or n.Class() == "Sphere" or n.Class() == "ReadGeo2":
			
			class dialog(object):
				window = nuke.Panel("Duplicate Geometry")
				window.addSingleLineInput("Clones:", 10)
			
			dialogResult = dialog.window.show()
			
			if dialogResult == 1:
				nuke.tprint("Duplicating Geometry...")
			else:
				nuke.tprint("Canceled")
				return None
			
			nodeYPos = n.ypos()
			nodeXPos = n.xpos()
			
			controlNode = nuke.createNode("NoOp")
			controlNode.knob("name").setValue("DuplicateGeometry")
			controlNode.knob('xpos').setValue(nodeXPos + 150)
			controlNode.knob('ypos').setValue(nodeYPos)
			
			controlNode.addKnob(nuke.Tab_Knob('Controls'))
			
			code = 'import random\nfor a in range(%s):\n a += 1\n TKnob = \"Translate_\" + str(a)\n RKnob = \"Rotate_\" + str(a)\n SKnob = \"Scale_\" + str(a)\n nuke.toNode(\"DuplicateGeometry\").knob(TKnob).setValue(random.uniform(-1, 1), 0)\n nuke.toNode(\"DuplicateGeometry\").knob(TKnob).setValue(random.uniform(-1, 1), 1)\n nuke.toNode(\"DuplicateGeometry\").knob(TKnob).setValue(random.uniform(-1, 1), 2)\n nuke.toNode(\"DuplicateGeometry\").knob(RKnob).setValue(random.uniform(-1, 1), 0)\n nuke.toNode(\"DuplicateGeometry\").knob(RKnob).setValue(random.uniform(-1, 1), 1)\n nuke.toNode(\"DuplicateGeometry\").knob(RKnob).setValue(random.uniform(-1, 1), 2)\n nuke.toNode(\"DuplicateGeometry\").knob(SKnob).setValue(random.uniform(-1, 1), 0)\n nuke.toNode(\"DuplicateGeometry\").knob(SKnob).setValue(random.uniform(-1, 1), 1)\n nuke.toNode(\"DuplicateGeometry\").knob(SKnob).setValue(random.uniform(-1, 1), 2)' % int(dialog.window.value("Clones:"))

			controlNode.addKnob(nuke.PyScript_Knob('Randomize', 'Randomize', code))
			
			controlNode.addKnob(nuke.XYZ_Knob('Translate'))
			controlNode.addKnob(nuke.XYZ_Knob('Rotate'))
			controlNode.addKnob(nuke.XYZ_Knob('Scale'))
			
			controlNode.addKnob(nuke.XYZ_Knob('TranslateRandom'))
			controlNode.addKnob(nuke.XYZ_Knob('RotateRandom'))
			controlNode.addKnob(nuke.XYZ_Knob('ScaleRandom'))
			
			for a in range(int(dialog.window.value("Clones:"))):
				a += 1
				TKnob = "Translate_" + str(a)
				RKnob = "Rotate_" + str(a)
				SKnob = "Scale_" + str(a)
				controlNode.addKnob(nuke.XYZ_Knob(TKnob))
				controlNode.addKnob(nuke.XYZ_Knob(RKnob))
				controlNode.addKnob(nuke.XYZ_Knob(SKnob))
				
				controlNode.knob(TKnob).setVisible(bool(0))
				controlNode.knob(RKnob).setVisible(bool(0))
				controlNode.knob(SKnob).setVisible(bool(0))
				
				controlNode.knob(TKnob).setValue(random.uniform(-1, 1), 0)
				controlNode.knob(TKnob).setValue(random.uniform(-1, 1), 1)
				controlNode.knob(TKnob).setValue(random.uniform(-1, 1), 2)
				controlNode.knob(RKnob).setValue(random.uniform(-1, 1), 0)
				controlNode.knob(RKnob).setValue(random.uniform(-1, 1), 1)
				controlNode.knob(RKnob).setValue(random.uniform(-1, 1), 2)
				controlNode.knob(SKnob).setValue(random.uniform(-1, 1), 0)
				controlNode.knob(SKnob).setValue(random.uniform(-1, 1), 1)
				controlNode.knob(SKnob).setValue(random.uniform(-1, 1), 2)
			
			scene = nuke.createNode("Scene")
			scene.knob('xpos').setValue(nodeXPos + 300)
			scene.knob('ypos').setValue(nodeYPos + 150)
			nuke.extractSelected()
			
			for i in range(int(dialog.window.value("Clones:"))):
				transform = nuke.createNode("TransformGeo")
				nuke.extractSelected()
				transform.knob('xpos').setValue(nodeXPos + 150)
				transform.knob('ypos').setValue(nodeYPos + (150 * (i + 1)))
				transform.setInput(0, n)
				
				scene.setInput(i, transform)
				
				vTranslate_0 = "DuplicateGeometry.Translate * " + str(i + 1) + " + DuplicateGeometry.TranslateRandom * DuplicateGeometry.Translate_" + str(i + 1)
				vTranslate_1 = "DuplicateGeometry.Translate * " + str(i + 1) + " + DuplicateGeometry.TranslateRandom * DuplicateGeometry.Translate_" + str(i + 1)
				vTranslate_2 = "DuplicateGeometry.Translate * " + str(i + 1) + " + DuplicateGeometry.TranslateRandom * DuplicateGeometry.Translate_" + str(i + 1)
				vRotate_0 = "DuplicateGeometry.Rotate * " + str(i + 1) + " + DuplicateGeometry.RotateRandom * DuplicateGeometry.Rotate_" + str(i + 1)
				vRotate_1 = "DuplicateGeometry.Rotate * " + str(i + 1) + " + DuplicateGeometry.RotateRandom * DuplicateGeometry.Rotate_" + str(i + 1)
				vRotate_2 = "DuplicateGeometry.Rotate * " + str(i + 1) + " + DuplicateGeometry.RotateRandom * DuplicateGeometry.Rotate_" + str(i + 1)
				vScale_0 = "1 + DuplicateGeometry.Scale * " + str(i + 1) + " + DuplicateGeometry.ScaleRandom * DuplicateGeometry.Scale_" + str(i + 1)
				vScale_1 = "1 + DuplicateGeometry.Scale * " + str(i + 1) + " + DuplicateGeometry.ScaleRandom * DuplicateGeometry.Scale_" + str(i + 1)
				vScale_2 = "1 + DuplicateGeometry.Scale * " + str(i + 1) + " + DuplicateGeometry.ScaleRandom * DuplicateGeometry.Scale_" + str(i + 1)
				
				transform.knob("translate").setExpression(vTranslate_0, 0)
				transform.knob("translate").setExpression(vTranslate_1, 1)
				transform.knob("translate").setExpression(vTranslate_2, 2)
				transform.knob("rotate").setExpression(vRotate_0, 0)
				transform.knob("rotate").setExpression(vRotate_1, 1)
				transform.knob("rotate").setExpression(vRotate_2, 2)
				transform.knob("scaling").setExpression(vScale_0, 0)
				transform.knob("scaling").setExpression(vScale_1, 1)
				transform.knob("scaling").setExpression(vScale_2, 2)