Adding entries to colorbands

I’m trying to write a script to manipulate colorbands, but I haven’t been able to figure out how to add entries to them.

#!BPY

“”"

Name: ‘Blend Interpolate’
Blender: 248
Group: ‘Misc’
Tooltip: ‘Creates a color in a colorband’
“”"
import BPyMesh
import Blender
import BPyMessages
reload(BPyMessages)
import bpy

from Blender import Scene, Mesh, Window, sys, Texture, Material

def main():

sce = bpy.data.scenes.active

 t = sys.time()

is_editmode = Window.EditMode()
Window.EditMode(0)

tex1 = Blender.Texture.Get('Test')

if not tex1:
    tex1 = Blender.Texture.New('Test')

#tex1.setFlags()

tex1.colorband.append( [.1,.1,.1,1,.5] )

Blender.Redraw()
print 'Interpolation finished in %.2f seconds' % (sys.time()-t)
Window.WaitCursor(0)
if is_editmode: Window.EditMode(1)

main()

the texture is created, but the colorband only contains the default entries.

It could be because you are passing an integer for your alpha value. Doesn’t and RGBA have to be all floats?


tex1.colorban.append([0.1,0.1,0.1,1.0,0.5])

Okay, I tried that and it doesn’t seem to help.

Looks like you are right, the append is failing.

If you print the contents of the color band, you get the default values.


def main():
 sce = bpy.data.scenes.active
 tex1 = Blender.Texture.Get('Test') #Assume Test already exists.
 myColorBand = tex1.colorband
 print myColorBand
 tex1.colorband.append( [0.1,0.1,0.1,1.0,.5] )

I figured it out

tex1 = Blender.Texture.Get(‘Test’)
colBand = tex1.colorband
colBand.append([0.1,0.1,0.1,1.0,0.5])
tex1.colorband = colBand

Thanks for your help.

Cool, you have to re-assign the colorband after you append to it.