# Problem with Vertex Coordinates

I'm using Blender 2.74 and trying to make this part of my code work:

import bpy
from math import *

me = bpy.ops.mesh.primitive_cylinder_add(radius = 0.5, depth = 1)

for v in me.verts:
v.co[2] =v.co[2]+0.5


But appear the folow error:'set' object has no attribute 'verts'.

What's the problem?

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 *

me = bpy.context.object.data

for v in me.vertices:
v.co[2] =v.co[2]+0.5


A few other things worth noting:

1. 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.
2. 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

3. 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.

4. [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

• Nice explanation @TLousky! The tips will help me a lot! Thanks ! :) – Jimmy Nov 11 '15 at 18:50
• No problem @Jimmy, added another small tip for good measure ;-) – TLousky Nov 11 '15 at 19:24