Getting AttributeError on very simple script (Blender 2.5)

Hi guys and gals

This is my first post here. I’m trying to learn how to use python in blender 2.5, starting from the very basics. adly, it hasn’t been easy. I’m getting errors on really simple programs, as this:


import bpy
import math
from math import *

def ejemplo():
    #define verts
    coords=[-1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0 ,-1.0, -1.0,1.0, -1.0, 0.0, 0.0, 1.0]
    #define faces
    faces=[ 2,1,0,3, 0,1,4,0, 1,2,4,1, 2,3,4,2, 3,0,4,3]
    me=bpy.data.meshes.new("Pyramid")# create a new mesh
    me.add_geometry(5, 0, 5) # add 5 vertices, 0 edges and 5 faces
    
ejemplo()

The message is the following:
Attribute Error : ‘Mesh’ object has no attribute ‘add_geometry’

Maybe the solution is quite simple

This works (with small changes)


import bpy
def createMesh(name, origin, verts, edges, faces):
    # Create mesh and object
    me = bpy.data.meshes.new(name+'Mesh')
    ob = bpy.data.objects.new(name, me)
    ob.location = origin
    ob.show_name = True
    # Link object to scene
    bpy.context.scene.objects.link(ob)

    # Create mesh from given verts, edges, faces. Either edges or
    # faces should be [], or you ask for problems
    me.from_pydata(verts, edges, faces)

    # Update mesh with new data
    me.update(calc_edges=True)
    return ob

import math
from math import *
from mathutils import Vector
def ejemplo():
    #define verts
    coords=[(-1.0, -1.0, -1.0), (1.0, -1.0, -1.0), (1.0, 1.0 ,-1.0),( -1.0,1.0, -1.0, 0.0),( 0.0, 1.0)]
    #define faces
    faces=[ (2,1,0,3), (0,1,4,0), (1,2,4,1), (2,3,4,2), (3,0,4,3)]
#    me=bpy.data.meshes.new("Pyramid")# create a new mesh
#    me.add_geometry(5, 0, 5) # add 5 vertices, 0 edges and 5 faces
    return createMesh("misandov",[0,0,0],coords,[],faces)
    
myobj = ejemplo()

createMesh taken from the code SNIPPETS !!!

Otherwise look at the addons building meshes!

Hi!

The code works, but I’d like to know what was wrong with it (so I don’t make mistakes like this again)

Thanks for the gentle and fast reply!

Could not find add_geometry (had seen it month ago and could not find back…, but all addons use from_pydata)