Updated May 2020
This was shockingly confusing. I mean it. You’d think there’d be a nice, simple way to plop coordinates into Blender to get a mesh. If there is, I wasn’t able to find it.
However, The Proving Ground has a really nice breakdown on the process because whoever runs that place is a damn saint.
The important bits to remember are basically this:
STEP 1: Create a Vertices Array with X,Y,Z Values for Each Point
Vertices = [(0,0,0),(0,1,0),(1,0,0),(1,1,1)]
STEP 2: Create a Faces Array to Tell Blender What Order to Connect Vertices In*
Faces = [(0,1,2,3)]
*The numbers within the parenthesis will connect to form a face. Remember, 0 = the first item in an array, so the 0 in Faces refers to (0,0,0).
STEP 3: Make a Mesh and Assign It to a Variable
EasyMeshVariable = bpy.data.meshes.new(“MeshName“)
STEP 4: Make an Object and Pop that Mesh into It*
EasyObjectVariable = bpy.data.objects.new(“ObjectName“, EasyMeshVariable)
*Alright, this is the part where I went a little rabid on Google because I hadn’t yet realized that meshes and objects are different things. Finally found the answer here. Basically, an Object is a Mesh + Material + Texture.
STEP 5: Set the Object Location to the Cursor Location
EasyObjectVariable.location = bpy.context.scene.cursor.location
STEP 6: Link the Object to the Current Scene
STEP 7: Push the Vertices and Faces Arrays into the Mesh
So if you ever have a dire need to make a three-sided face with far too many lines of code, just follow that template. Like so:
You may have noticed that the vertices array has an extra point at (1,1,1,). Since the faces array doesn’t have a 3 (the 4th item in the vertices array), Blender doesn’t connect that vertex.
Here’s where things can get wonky. Connect the vertices in a bad order and you might get this problem:
If this happens it’s actually a really easy fix. Just switch around the order in the faces array.
That’s it in a nutshell. But the real fun comes in plugging formulas into the vertex array for crazy meshes. I use “fun” here to mean “torture” if you hate math.
A Working Example: The ExpPlanes Function
So if say, you run x,y,z, values through a while loop and use the .append function to push coordinates into the vertices array, you can get hundreds of points with not that much code. The tricky part is pushing the right numbers into the faces array so that it’ll display everything as intended.
Here’s a function that makes multiple planes within the same mesh at precise intervals on the Z axis. X and Y remain constant.
import bpy #z equals the z axis increments for each plane #height equals the z value of the highest plane #size equals size of planes #sinc equals how much to increment size by as z gets higher def expplanes(zinc,height,size,sinc): vertices =  faces =  z=0 x=0 y=0 index=0 while index<=height: vertices.append([x,y,z]) vertices.append([x+size,y,z]) vertices.append([x+size,y+size,z]) vertices.append([x,y+size,z]) faces.append([index,index+1,index+2,index+3]) z+=zinc size+=sinc index+=4 print(vertices) EasyMeshVariable = bpy.data.meshes.new("MeshName") EasyObjectVariable = bpy.data.objects.new("ObjectName", EasyMeshVariable) EasyObjectVariable.location = bpy.context.scene.cursor.location bpy.context.collection.objects.link(EasyObjectVariable) EasyMeshVariable.from_pydata(vertices,,faces) expplanes(.5,50,2,.1)
This uses an index variable to deal with the faces array. Add 4 to index at the end of every loop and it’ll jump forward to the next set of 4 vertices to create a separate plane.
What in the hell good is this, you ask? Well, I’m thinking a creepy spaceship like this guy: