My first script for create lines from vertices.

Hello!I’m a total script newbie.
This 's my first blender script for create lines from vertices.
We need a object just containing several points(no edge better), then active it and run script.

This script is working fine, but maybe not high-efficiently.
Any suggestions will be appreciated!


import bpy

ob = bpy.context.object
verts = ob.data.vertices
bpy.context.tool_settings.mesh_select_mode=[True,False,False] #vertexmode

for i in range(0, len(verts)-1):
    verts[i].select = verts[i+1].select = True
    bpy.ops.object.editmode_toggle()
    bpy.ops.mesh.edge_face_add()
    bpy.ops.mesh.select_all(action='DESELECT')
    bpy.ops.object.editmode_toggle()

Bump! Gonna try it, thanks buddy. :slight_smile:

how does it work ?
i mean your not reading cursor

happy 2.5

I am also very new to Blender scripting, I try to find various examples, and rewrite them as clean as possible for readability. Here’s how you can make a default cube, ala Python:


import bpy

scene = bpy.context.scene

# Create the mesh
mesh = bpy.data.meshes.new('MyMesh')

# Create the object
object = bpy.data.objects.new('MyObject', mesh)

# Add vertices
verts = (
    (-1,-1, -1),  # 0 
    ( 1,-1, -1),  # 1
    ( 1, 1, -1),  # 2
    (-1, 1, -1),  # 3
    
    (-1,-1, 1),  # 4
    ( 1,-1, 1),  # 5
    ( 1, 1, 1),  # 6
    (-1, 1, 1)   # 7
)

# Faces
faces = (
    (0, 1, 2, 3),   # Bottom
    (4, 5, 6, 7),   # Top
    (0, 3, 7, 4),   # Left
    (1, 2, 6, 5),   # Right
    (2, 3, 7, 6),   # Forward
    (0, 1, 5, 4)    # Backward
)

# Load data (Vertices and Faces)
mesh.from_pydata(verts, (), faces)

# Link new object with the scene
scene.objects.link(object)

To RickyBlender:
This script is used to connect several points that already exist. Just a newbie’s script study test.
We need a object just containing several points(no edge better), then active it and run script.

To flopoloco:
Thanks buddy! I’ve tested “mesh.from_pydata”.
But I think this feature is a structure when creating a new mesh.

So.I use “select” and “edge_face_add”.
This script is a action replayer. not a real inside “get vertices - output edges” script.
This’s not a high-efficiently way.Is there another way?

happy 2.5 :slight_smile: