I’m trying to learn some scripting so I thought that a nice simple first step would be to modify an existing material node script. I am “simply” trying to take the 10 way texture switcher and increase it to accept 20 textures:
http://blenderartists.org/forum/showthread.php?t=155800
But every time I make changes I am stimied by indent errors! Here is what I’ve come up with :
http://www.filefront.com/14656425/NodalSwitchBox20f.py
Is there a limit to line length with python scripts or in Pythin itself? Perhaps that is the problem, I don’t know I am getting rather frustrated. I can’t figure out how to post text here and have the indents maintained so I appologize about the double wide screenshots but since you can’t use wordwrap I can think of no other way of showing you where I am getting the errors. First the error message seems to be in the long definition line but doesn’t go away when I shorten it:
And again sorry for the huge images, the actual script:
and here is the script as text:
#"""
#Name: ‘20Way Nodal Frame Switch’
#Blender: ‘248-249’
#Group: ‘Animation’
#Tooltip: ‘Edit the values in the script below in the section User Definable Variables to work’
#"""
#author = “expanded to 20 textures by Lyle Walsh” “from the 10Way Nodal Frame Switch- written by Holly Tsukiko Grimes”
#url = [“Fairytalecomics, http://www.fairytalecomics.com/”]
#version = “0.96”
#bpydoc = “”\
#Description:
#This is merely an expansion of the 10Way Nodal Frame Switch - which works as a texture multiplexer material node that outputs
#one of 20 textures depending on the frame number. Note each texture must first be saved in a dummy material and set to fake ‘F’
#What follows is the original 10way nodal switch description for version 0.95:
"A nodal version of my script from http://blenderartists.org/forum/showthread.php?t=141472
#This is a simple node that allows one to select a colour/texture/value
#to use in a node map depending on the current frame of the animation i.e
#A 10-way switch based on the current frame.
#This version is simplier, easier to use and customise and can be used
#for any colour or float-value in a node map compared to the original
#script.
#You simply edit the array below to have a range of frames you want that
#‘channel’ of the node to be active. If the current frame isn’t in the array
#the node automatically forwards the ‘Base’ Channel so something is always
#forwarded. The array works in pairs, so you have to set a start frame and an
#end frame (inclusive).
#If you have more than 1 channel indicated for a frame, the switcher only chooses
#the first instance of it eg if channels 3 and 5 are in the array as active for
#frame 32, channel 3 is used.
#Drawbacks: cannot be used in glsl textures or previewing on the fly due to the amount of
#computations needed per pixel. I’m hoping to speed this up in the future.
#There is a glitch in which the texture detail forwarded is corrupt due to poor multithread support
#from python, make sure you only use 1 thread if you wish to use this node.
#Revisions 0.9->0.95: corrected a glitch in which wrong channel is selected due to the indices being
#off in the searcher"
import Blender
from Blender import *
from Blender import Node
######################################################
#User Definable Variables
#Edit these values for your own personalised node
######################################################
#Example array information
#(note: do not change name of array)
#Base= Base texture Colour (not shown but is active on frames 1-10, 211+)
#1= texture 1 active on frames 11-20
#2= texture 2 active on frames 21-30
#3= texture 3 active on frames 31-40
#etc, etc, cycling through the 20 input textures each 10 frames
FrameInfoArray=[
[11,20],
[21,30],
[31,40],
[41,50],
[51,60],
[61,70],
[71,80],
[81,90],
[91,100],
[101,110],
[111,120],
[121,130],
[131,140],
[141,150],
[151,160],
[161,170],
[171,180],
[181,190],
[191,200],
[201,210]]
######################################################
#Main Node class
#Doesn’t need to be changed. Its automatically set up
#for 10 fields, inc the base field, more can be achieved
#but one would need to extend the arrays
######################################################
class FTextureChanger(Node.Scripted):
def init(self, sockets):
colB = Node.Socket(‘TexBase’, val = 4*[1.0])
col1 = Node.Socket(‘Tex1’, val = 4*[1.0])
col2 = Node.Socket(‘Tex2’, val = 4*[1.0])
col3 = Node.Socket(‘Tex3’, val = 4*[1.0])
col4 = Node.Socket(‘Tex4’, val = 4*[1.0])
col5 = Node.Socket(‘Tex5’, val = 4*[1.0])
col6 = Node.Socket(‘Tex6’, val = 4*[1.0])
col7 = Node.Socket(‘Tex7’, val = 4*[1.0])
col8 = Node.Socket(‘Tex8’, val = 4*[1.0])
col9 = Node.Socket(‘Tex9’, val = 4*[1.0])
col10 = Node.Socket(‘Tex10’, val = 4*[1.0])
col11 = Node.Socket(‘Tex11’, val = 4*[1.0])
col12 = Node.Socket(‘Tex12’, val = 4*[1.0])
col13 = Node.Socket(‘Tex13’, val = 4*[1.0])
col14 = Node.Socket(‘Tex14’, val = 4*[1.0])
col15 = Node.Socket(‘Tex15’, val = 4*[1.0])
col16 = Node.Socket(‘Tex16’, val = 4*[1.0])
col17 = Node.Socket(‘Tex17’, val = 4*[1.0])
col18 = Node.Socket(‘Tex18’, val = 4*[1.0])
col19 = Node.Socket(‘Tex19’, val = 4*[1.0])
col20 = Node.Socket(‘Tex20’, val = 4*[1.0])
colO = Node.Socket(‘Colour’, val = 4*[1.0])
ValB= Node.Socket(‘ValueBase’, val = 1.0, min = 0.0, max = 1.0)
Val1= Node.Socket(‘Value1’, val = 1.0, min = 0.0, max = 1.0)
Val2= Node.Socket(‘Value2’, val = 1.0, min = 0.0, max = 1.0)
Val3= Node.Socket(‘Value3’, val = 1.0, min = 0.0, max = 1.0)
Val4= Node.Socket(‘Value4’, val = 1.0, min = 0.0, max = 1.0)
Val5= Node.Socket(‘Value5’, val = 1.0, min = 0.0, max = 1.0)
Val6= Node.Socket(‘Value6’, val = 1.0, min = 0.0, max = 1.0)
Val7= Node.Socket(‘Value7’, val = 1.0, min = 0.0, max = 1.0)
Val8= Node.Socket(‘Value8’, val = 1.0, min = 0.0, max = 1.0)
Val9= Node.Socket(‘Value9’, val = 1.0, min = 0.0, max = 1.0)
Val10= Node.Socket(‘Value10’, val = 1.0, min = 0.0, max = 1.0)
Val11= Node.Socket(‘Value11’, val = 1.0, min = 0.0, max = 1.0)
Val12= Node.Socket(‘Value12’, val = 1.0, min = 0.0, max = 1.0)
Val13= Node.Socket(‘Value13’, val = 1.0, min = 0.0, max = 1.0)
Val14= Node.Socket(‘Value14’, val = 1.0, min = 0.0, max = 1.0)
Val15= Node.Socket(‘Value15’, val = 1.0, min = 0.0, max = 1.0)
Val16= Node.Socket(‘Value16’, val = 1.0, min = 0.0, max = 1.0)
Val17= Node.Socket(‘Value17’, val = 1.0, min = 0.0, max = 1.0)
Val18= Node.Socket(‘Value18’, val = 1.0, min = 0.0, max = 1.0)
Val19= Node.Socket(‘Value19’, val = 1.0, min = 0.0, max = 1.0)
Val20= Node.Socket(‘Value20’, val = 1.0, min = 0.0, max = 1.0)
ValO= Node.Socket(‘ValueOut’, val = 1.0, min = 0.0, max = 1.0)
sockets.input = [ValB,colB,Val1,col1,Val2,col2,Val3,col3,Val4,col4,Val5,col5,Val6,col6,Val7,col7,Val8,col8,Val9,col9,Val10,col10,Val11,col11,Val12,col12,Val13,col13,Val14,col14,Val15,col15,Val16,col16,Val17,col17,Val18,col18,Val19,col19,Val20,col20]
sockets.output = [ValO, colO]
def call(self):
def checkframes(frameno, FrameArray):
Texno=-1
found=0
for Lnum in range(0,len(FrameArray)):
for Fnum in range(0,len(FrameArray[Lnum])/2):
if found==0:
if int(frameno) >= FrameArray[Lnum][(Fnum)*2] and int(frameno) < FrameArray[Lnum][((Fnum)*2)+1]:
Texno=Lnum
found=1
return Texno
scn= Blender.Scene.GetCurrent()
currframe=str(Blender.Get(‘curframe’))
ColourinputArray=[self.input.Tex1, self.input.Tex2, self.input.Tex3, self.input.Tex4,self.input.Tex5,self.input.Tex6,self.input.Tex7,self.input.Tex8,self.input.Tex9,self.input.Tex10,self.input.Tex11,self.input.Tex12, self.input.Tex13, self.input.Tex14,self.input.Tex15,self.input.Tex16,self.input.Tex17,self.input.Tex18,self.input.Tex19,self.input.Tex20]
ValueinputArray=[self.input.Value1, self.input.Value2, self.input.Value3, self.input.Value4,self.input.Value5,self.input.Value6,self.input.Value7,self.input.Value8,self.input.Value9,self.input.Value10,self.input.Value11, self.input.Value12, self.input.Value13, self.input.Value14,self.input.Value15,self.input.Value16,self.input.Value17,self.input.Value18,self.input.Value19,self.input.Value20]
Texnumber= checkframes(currframe, FrameInfoArray)
if Texnumber!=-1:
self.output.Colour = ColourinputArray[Texnumber]
self.output.ValueOut = ValueinputArray[Texnumber]
else:
self.output.Colour = self.input.TexBase
self.output.ValueOut = self.input.ValueBase
node = FTextur eChanger