How to create a simple grid in Blender 2.50 through the Python API

I would like to create a simple grid in Blender (2.50) through the Python API, but the examples from the API documentation still do not work.

I tried the following, but from API 2.49

from Blender import * import bpy editmode = Window.EditMode() # are we in edit mode? If so ... if editmode: Window.EditMode(0) # leave edit mode before getting the mesh # define vertices and faces for a pyramid coords=[ [-1,-1,-1], [1,-1,-1], [1,1,-1], [-1,1,-1], [0,0,1] ] faces= [ [3,2,1,0], [0,1,4], [1,2,4], [2,3,4], [3,0,4] ] me = bpy.data.meshes.new('myMesh') # create a new mesh me.verts.extend(coords) # add vertices to mesh me.faces.extend(faces) # add faces to the mesh (also adds edges) me.vertexColors = 1 # enable vertex colors me.faces[1].col[0].r = 255 # make each vertex a different color me.faces[1].col[1].g = 255 me.faces[1].col[2].b = 255 scn = bpy.data.scenes.active # link object to current scene ob = scn.objects.new(me, 'myObj') if editmode: Window.EditMode(1) # optional, just being nice 

This does not work because the mesh object does not have faces or verts .

Are there any options for this?

+6
python blender
source share
2 answers

Try this documentation for the 2.5x API. I understand that despite the big warnings at the top, the most frequently used partitions are pretty stable. I have not tried it yet.

EDIT:

I think the corresponding bit is this section - it seems you are creating a list of vertex faces, etc. and pass it on to this. This seems to have changed from the most recent examples I can find. Try to look in the folder with your scripts - there may be an example that you can look at.

EDIT 2: I updated the link to point to current documents. The notes there suggest that there are probably better ways to do this now, but I haven't done any blender scripts for a long time, so I can't help anymore.

+3
source share

Thanks to neil, I found the following section from the documentation:

Scripts for Blender 2.50 - Adding Scripts to the Grid

I will try the following script and report my results:

Add Solid Object Mesh

+1
source share

All Articles