Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created August 9, 2011 06:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zeffii/1133518 to your computer and use it in GitHub Desktop.
Save zeffii/1133518 to your computer and use it in GitHub Desktop.
adding polyline in blender 2.5
import bpy
from mathutils import Vector
listOfVectors = [((0,0,0,1)),((1,0,0,1)),((2,0,0,1)),((2,3,0,1)),((0,2,0,1))]
# create a spline curve from a number of points
def MakePolyLine(objname, curvename, cList):
curvedata = bpy.data.curves.new(name=curvename, type='CURVE')
curvedata.dimensions = '2D'
objectdata = bpy.data.objects.new(objname, curvedata)
objectdata.location = (0,0,0) #object origin
bpy.context.scene.objects.link(objectdata)
polyline = curvedata.splines.new('POLY')
polyline.points.add(len(cList)-1)
for num in range(len(cList)):
polyline.points[num].co = (cList[num])
polyline.order_u = len(polyline.points)-1
polyline.use_endpoint_u = True
polyline.use_cyclic_u = True
MakePolyLine("NameOfMyCurveObject", "NameOfMyCurve", listOfVectors)
@pskl
Copy link

pskl commented Apr 11, 2018

Why do the vectors need to have 4 dimensions?

@amastrobera
Copy link

amastrobera commented Aug 22, 2018

the api doesn't take others. probably because it works on this theory... You can shift and rotate a 3D vector via a 4x4 matrix; then you must transform your 3D vector into a 4D one (with a default last argument = 1, you will notice).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment