Script to Import 3D Point List to Curve

(Skwerm) #1

Greetings, all!

I need a script that will parse a sorted ASCII point list that contains X,Y,Z information for points along a 3D Curve and then create that 3D curve in Blender.

Does anything like this exist? If not, I’d be willing to negotiate a fee for producing the script for me.

Thanks.

0 Likes

(tolobán) #2

Easy to adapt from a script that made hair curves from edgeloops in a mesh

import Blender

def loadPoints(file):
  f = Blender.Text.Load(file)
  points = []
  for l in f.asLines():
      coords = l.split()
      x= float(coords[0])
      y= float(coords[1])
      z= float(coords[2])
      points.append([x,y,z, 1.0])
  Blender.Text.unlink(f)

  if len(points) < 4:
     Blender.Draw.PupMenu('%tFile contains less than four control points')
     return

  curveOb = Blender.Object.New('Curve')
  Blender.Scene.GetCurrent().link(curveOb)
  curve = curveOb.getData()
  curve.appendNurb(points[0])

  for p in points[1:]:
     curve[0].append(p)

  Blender.Redraw()

Blender.Window.FileSelector(loadPoints, 'Text coordinates file')

0 Likes

(Skwerm) #3

Thanks for the example code! I’ll blow the dust off of my Python knowledge (I used to be pretty good at it!) and give it a go.

BTW, does anyone know if there’s a limit to the number of points in a curve?

Cheers!

0 Likes

(forTe) #4

Some of those methods are now deprecated. Try looking in the curve module documentation here: http://www.blender.org/documentation/244PythonDoc/index.html. To see the updated methods. Note that only a couple need this, and the arguments won’t really change to the functions that do, but its always good form to write modern code.

0 Likes