manipulate vertices with a for statement?

Hello, is it possible to manipulate the vertices in a selected mesh individually by iterating through a for statement? I am new to python and I cannot figure out any way of doing this or anything similar… Thanks a lot!

Sure you can, there are plenty of examples… and it’s fun, try this tiny script with a torus:

import bpy, random
obj = bpy.context.object
ver = obj.data.vertices
escala = 0.25

for v in ver:
    v.co[0] += escala*(random.random()*2-1)
    v.co[1] += escala*(random.random()*2-1)
    v.co[2] += escala*(random.random()*2-1)

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.vertices_smooth(repeat=10)
bpy.ops.object.mode_set(mode='OBJECT')

That is a way of doing it, you can access by vertex index too, something like:

for i in range(len(ver)):
    ver[i].select = True

is there a way to access selected vertices in edit mode then play with these?

like you go into edit mode then select some vertices in viewport and you want to do something with these selected vertices
some operations
like change shape into a circle , square ellipse or other things!

interesting
that you don’t really have to go into edit mode when using bpy but you do when using BPY OPS!

thanks happy 2.5

you can do some nice circles from a selection with Alt+Shift+S and dragging…
and I don’t really have a clue about python, just find it fun to play with

ok but if you can get selected vertices from viewport
the you can play with these andd o whatever you want

so is there a way to get the selected vertices in edit mode from viewport on mesh ?

thanks

I think you may need to to switch modes, something like this:


import bpy
ver = bpy.context.object.data.vertices
em = (bpy.context.mode == 'EDIT_MESH')
if em : bpy.ops.object.mode_set()

print ('----------------------------')
for v in ver:
    if v.select:
        print('vertex', v.index, 'is selected')

if em : bpy.ops.object.editmode_toggle()

i’ll try this tomorrow later
but looks interesting enough

hope it works ok

mind you there might be another way using only bpy.ops too!

but in a way i prefer this way cause it’s faster i think then using operators!

thanks happy 2.5

this is working


 
 
import bpy
 
 
import bpy
from mathutils import Vector
from bpy.props import *
 
scene = bpy.context.scene
 
 
ob = bpy.context.active_object
ver = bpy.context.object.data.vertices
em = (bpy.context.mode == 'EDIT_MESH')
if em : bpy.ops.object.mode_set()
print ('----------------------------')
for v in ver:
    if v.select:
        print('vertex', v.index, 'is selected')
if em : bpy.ops.object.editmode_toggle()
 
 

very nice example

what is this em thing
is it predefined word from API
or just a var ?

have a look on this one too for edges creation

http://blenderartists.org/forum/showthread.php?t=210331

thanks