Set location of vertices, accessing object's data

Hello,
I’m absolutely new beginner, and I’d like to ask some general questions.

  1. Is there a way to access object’s data like position of it’s vertices? (I see bpy.data.objects[‘something’], but don’t know what to do next).

  2. I’d like to know whether there is an operator to set position of object’s vertices (not move, but set).

I know these are noob questions, but I can’t find any relelvant info on wiki…

Thanks for your time and patience,

Skyer

Setting and moving vertices is the same exact thing. If you set a location for a vertex you have moved it if the new location is different from the previous location.


import bpy

ob = bpy.data.objects["Cube"]
me = ob.data
print("faces:")
for face in me.faces:
    print(face)

print("
verts:")
for vert in me.vertices:
    new_location = vert.co
    new_location[0] = new_location[0] + 1   #X
    new_location[1] = new_location[1] + 1   #Y
    new_location[2] = new_location[2] + 1   #Z
    vert.co = new_location

NOTE: vert.co stands for the vertex coordinate.

Comments related to Atoms nice answer:

If you have (x,y,z) the ‘new’ coordinates of your vertex already computed/available
you can use at once: vert.co = (x,y,z)
(or if “from mathutils import Vector” is done)
I would write Atoms example as
vect.co = vect.co + Vector((1,1,1))
:wink:

Thank you both, exactly what I wanted to know.

By the way, this Python integration makes Blender extremely usable, I’m planning to create a module to calculate triangle’s sides and angles :).

Skyer

angles and lengths are already ‘built in’ use in 3DView and type N (such that the right options are visible) and under Display in edit-mode you can see angles and length …(select works too!)

Though I do not know yet to get the measurements to Python …

Huh,
which version of Blender are you using? I can’t find anyting like it. The display section of “N panel” doesn’t seem to contain any information about angles or lenghts. I attached a screen to see what am I missing…

//edit: the whole thing shouldn’t be hard to do in Python, we know coordinates of all points, so we can easily get the rest.

Skyer

Attachments


moment …

Just compile 2.61 :wink:

this is while dragging the vertices, if finished, less is shown (only used selection used)!

You may need to run this little script first. Then open up Mesh Display.


import bpy
bpy.app.debug = True

Setting debug = True gets you some extra numerics.

Alright,
I am already using Blender 2.61, but turning on debugging fixed it. Great. (Looks like I won’t even have to, actually, do any work after all :D).

Thanks for your help,

Skyer