2
$\begingroup$

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.

$\endgroup$

2 Answers 2

4
$\begingroup$

some good reference: adding geometry

note that you must be in editmode (EDIT: to go to edit mode, create a mesh, select it with right-click, and then hit "tab"), and remove doubles after run the script:

import bpy, bmesh

obj = bpy.context.object
me = obj.data
bm = bmesh.from_edit_mesh(me)

v1 = bm.verts.new((2.0, 2.0, 2.0))
v2 = bm.verts.new((-2.0, 2.0, 2.0))
v3 = bm.verts.new((-2.0, -2.0, 2.0))


bm.edges.new((v1, v2))
bm.edges.new((v2, v3))

bmesh.update_edit_mesh(obj.data)

if you have the point list, may be you can apply some loops

$\endgroup$
1
-1
$\begingroup$

See documentation

bge.render.drawLine(fromVec, toVec, color) Draw a line in the 3D scene.

Parameters:

fromVec (list [x, y, z]) – the origin of the line

toVec (list [x, y, z]) – the end of the line

color (list [r, g, b]) – the color of the line

import bge
bge.render.drawLine([0,0,0],[0,0,1],[255,40,0])
#note: [255,40,0] is red in RGB
$\endgroup$
1
  • 3
    $\begingroup$ This is for 2D drawing in the game engine, not for creating a mesh. I believe that OP wanted to create a mesh. $\endgroup$ Jan 5, 2018 at 2:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .