Altering Curve Nurbs via Python

Hello Everyone,

I have a python question. I am writing a script that will read a CSV file into blender as a Nurbs Curve. After assigning a bevel object I will render a snap shot, I got that working well but now I want to read in a sequence of files and perform that same set of operations on each file, and then remove the curves I generated and make the next set. I got it to work by unlinking the curves after each file but this eats up a LOT of my memory as I do more and more files. My thought is to read in each file and simply edit the nurbs of the curves I originally created with the first file (they all have exactly the same number of points). But I am having a lot of trouble getting blender to edit the individual NURBS. I have named the curves Curve, Curve1…Curve10. Here is my code attempting to edit the NURBS. The result I get is the exact same image each time. (also see below)

file = open(path_file, ‘r’)
line = file.readline() #skip the first line
line = file.readline()
words = line.split(’,’)
cu= Curve.get(“Curve”) #get first curve
while file:
line = file.readline()
words = line.split(’,’)
if n>1:
cu_nurb[NURB_count]=a #Add the New NURBS
elif n<=1:
if words[0]==‘Start
‘: #signifies the start of the next curve object
cu_nurb.setFlagU(1)#make cyclical
cu.setFlag(15) #adjust visualization properties
scn= Scene.GetCurrent()
cu= Curve.get(“Curve” + str(Curve_count))
line = file.readline()
words = line.split(’,’)
cu_nurb[0]=([float(words[0]),float(words[1]),0,50]) # We must add with a point to #start with
context = scn.getRenderingContext()

enable seperate window for rendering

context.imageType = Render.JPEG

draw the image


save the image to disk

to the location specified by RenderPath

by default this will be a jpg file

context.saveRenderedImage(name_render[0] + ‘.jpg’)
scene = Scene.GetCurrent()

Now I understand that I should have the line cu_nurb=cu[0] to define cu_nurb to the specific curve but when I do that I get an error saying “Index Error:no Nurbs in this Curve”

I guess this was a really long winded way of asking how to resolve the above error.


Thanks in advance

Sorry the above code lost all its indentations! The main issue I am trying to resolves is the error that takes place below the code.


Also I am using Blender 2.49b

Hello All,

I figured it out. it was a coding mistake and cu_nurb=cu[0] does infact work, but I was grabbing an empty curve that I was generated without my knowledge that did not have any NURBS.

Please ignore this question.