If you print out the content of me
in the console, you can see that it does not contain the cylinder's mesh data:
>>> me
{'FINISHED'}
The bpy.ops.mesh.primitive_cylinder_add
operator, like most operators in Blender, returns its exit status (in our case {'FINISHED'} - signalling success) rather then the result of whatever it did.
If you want to access the vertices, you can do this through bpy.context.object.data.vertices
, since after you add a cylinder primitive, it becomes the active object (context.object):
import bpy
from math import *
bpy.ops.mesh.primitive_cylinder_add(radius = 0.5, depth = 1)
me = bpy.context.object.data
for v in me.vertices:
v.co[2] =v.co[2]+0.5
A few other things worth noting:
- The vertex collection in the mesh object's data is called vertices (For instance:
context.object.data.vertices
) not verts. The bmesh module does call the vertex collection verts, which is probably why this confused you.
It's considered bad practice to import everything from a module, unless you're actually going to use everything you imported (from math import *
). You should only import whatever function you intend to use. For instance:
from math import degrees, radians
Small tip regarding debugging in blender (and in general):
The error message you got gave you a nice lead for debugging. It says that whatever it is you're trying to use .verts
with doesn't really have any attribute called 'verts'. The next logical thing is to check what the heck is inside the me
variable by printing it, to see why it has no verts. This would have showed that me
is indeed a set, not a mesh data object, which whould have indicated that the bpy.ops.mesh.primitive_cylinder_add
operator returns an exit status, and not the cylinder's data.
[EDIT] And another late one. To get a shorter and more readable version of your scaling action, you can replace this:
v.co[2] =v.co[2]+0.5
With this:
v.co.z += 0.5