Drawing a simple 3d line using Python

I would like to draw a simple line using Python script code.
I would like to draw the line from (0,0,0) to (0,0,1)

My philosophy (from what I’ve seen on the net) is: Draw a mesh plane (center at (0,0,0))
Select and delete 3 of the 4 vertices (Edit Mode)
Snap (move) the remaining vertex to the center of the plane (original placement point)

  • snap cursor to center
  • select and snap remaining vertex to cursor (now at the center)
    Extrude the current vertex to (0,0,1)

I come from a CAD world, so this seems complicated for a simple object like a line, but I’m willing to adapt.
My general task is to draw “stick figures” using lines (between named points).
Being able to “name” the points would be a plus, so I can draw new lines starting from those named points when needed.

Ultimately, I would like to be able to import a spreadsheet/csv file with point data and plot the stick figures, where
each point could have a name, and the final figure would also have a name for later referencing.

Please advise if this is not the appropriate place to post this request.

Thanks in Advance.

[QUOTE][/QUOTE]Unfortenately I have not figured out how to update meshes from bpy.object modification. but I can awnser your question for every line use scene.post_draw.append(lambda:bge.render.drawLine(3dcoord,(r,g,b)))

you can read data from CVS or txt file then make some lines with it as a mesh for an object

but you cannot add a name for each edge or verts in blender
name are only for object only

can you show some pic of what you want to do !

happy bl

Did you checked how “mesh.from_pydata” works ?


What you can do is :

For every point in you csv file, create a new object with only 1 vertex positioned at x, y, z:me = bpy.data.meshes.new(name_of_the_point)
me.from_pydata(([0,0,0]),[], [])
ob = bpy.data.objects.new(name_of_the_point, me)
ob.location = x, y, z
Then for every line you need to draw between two points, create a bezier curve between the two point. One way to do it is to create a mesh with 1 edge between the two point and convert it a curve :
co1 = bpy.data.objects.get(name_of_the_point1).location.copy()
co2= bpy.data.objects.get(name_of_the_point2).location.copy()

me = bpy.data.meshes.new(curve_name);
ob = bpy.data.objects.new(curve_name, me)

vertices = [co1, co2];
edges = [0, 1];
me.from_pydata(vertices, edges, []);

ob.select = True;
bpy.context.scene.objects.active = ob

ob.data.fill_mode = ‘FULL’
ob.data.bevel_depth = 0.1 # for instance

To the referencing of the final figure, you can create an empty, and parent all points and lines to it. Then yo can move the empty to move the whole model.

This is a very basic way of doing and with than you can’t neither animate the point to animate the lines nor rig the animation.