Last active
April 3, 2019 08:25
-
-
Save draconiansolo/5658810 to your computer and use it in GitHub Desktop.
Nuke Python for artists tutorials Manipulating the node graph with opinionated comments and notes in spanglish.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#n1=nuke.nodes.NoOp(xpos=0,ypos=0) #creates a NoOp node at 0,0... | |
# xpos and ypos are hidden knobs. | |
n1=nuke.nodes.NoOp(xpos=0,ypos=0,label='0,0') #label pa marcarlo, not that it matters. | |
n2=nuke.nodes.NoOp(xpos=200,ypos=200,label='200,200') #same | |
############# | |
marker=nuke.nodes.Dot() #crear un dot | |
############## | |
marker.knob('xpos').setValue(100) #change xpos as a knob | |
############## | |
marker.setXpos(0) | |
marker.setYpos(0) #also there are special functions for that | |
############### | |
marker.setXYpos(10,10) #and for modifying both at the same time | |
############### | |
width=n2.screenWidth() #this variable stores the width of a node | |
marker.setXYpos(n2.xpos()+width,n2.ypos()) #so i can place nodes in respect to each other | |
############ | |
nuke.zoom() #returns current zoom | |
nuke.zoom(2)# | |
nuke.zoom(0.1)# applies zoom | |
nuke.zoom(0.5,(marker.xpos(),marker.ypos())) #applies zoom to value + tuple or list of centrerpoint coordinates | |
nuke.zoom(0) #or negative = zoom to fit | |
##################### | |
for n in nuke.allNodes(): #from all nodes | |
nuke.delete(n) #delete all... | |
######################## | |
######## function to scale node threes and stuff. #################### | |
def scaleNodes(factor): #define function and parameters | |
nodes=nuke.selectedNodes() #grab the selected nodes into a variable | |
if len(nodes)==0: #if the lenght of the selected node list is 0 | |
return #the function does nothing | |
sumX=0 #sumatoria de valores de x | |
sumY=0 #sumatoria de valores de y | |
for n in nodes: #de todos los nodos | |
sumX+=n.xpos() #sumo | |
sumY+=n.ypos() #y sumo y sumo | |
centerX=sumX/len(nodes) | |
centerY=sumY/len(nodes) #para sacar promedios... o sea los centros | |
for n in nodes: # para cada nodo | |
n.setXpos(centerX+(n.xpos()-centerX)*factor) | |
n.setYpos(centerY+(n.ypos()-centerY)*factor) #escalo la posicion con respecto al centro | |
menu=nuke.menu('Nuke') #get the menu | |
menu.addCommand('Edit/Node/Loosen Nodes','scaleNodes(1.5)','ctrl+=') | |
menu.addCommand('Edit/Node/Tighten Nodes','scaleNodes(0.75)','ctrl+-')#add commands | |
#this bit can be added to menu.py to get the node scaling function thing. | |
###############dot spiral thingy################## | |
import math | |
for x in range(1000): #will do nothing in PLE :( | |
n = nuke.nodes.Dot() | |
n.setXYpos(math.sin(x)*x/2, math.cos(x)*x/2) | |
n['hide_input'].setValue(True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment