How to create/draw just a line

Hi,

I’m looking for a method to draw lines between objects in normal editing mode (no game engine mode).
These lines are sort of temporary helping lines for creating objects.

I assume I can not do that with the openGL library (bgl), because then I need to do that each time the view changes.
And I have no idea how to do that.

I found this example on the forum:

scn = bpy.Context.Scene.GetCurrent()
me = bpy.Mesh.New(‘line’)

def drawLine(mes, p1, p2):
mes.verts.extend(p1, p2)
mes.edges.extend(-1, -2)

drawLine(me, [0, 1, 2], [3, -2, 1])
scn.objects.new(me, ‘LineObj’)

But this gives errors because of none existing functions. So I guess it is old.

Can I create a mesh with only vertexes and lines draw between them?
I know how to create meshes containing vertexes and faces. But how to define only lines?
Is that possible?

Can I use a Curve for this? I can not find any examples how to add a simple curve to the Scene.

do you mean verts and EDGES? You could e.g.

import bpy

bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.mesh.primitive_cube_add()
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.delete(type='ONLY_FACE')
bpy.ops.object.editmode_toggle()