Previous Thread  Next Thread

chat icon Selecting a specific vertex

CallMeMisterX

Posted: Sat Aug 11, 2012 7:24 pm
Joined: 07 Apr 2012
Posts: 4
Hello, I have been searching and can't seem to find how to select specific vertices of a mesh.

What I'm trying to do:
I am first adding a cylinder primitive with end fill set to "TRIFAN". Once this is completed, I want to then be able to select the center vertex in order to move it downward, effectively creating a pin/point. The problem is finding a way to select the center vertex in order to reposition it and pull this off. Any help is greatly appreciated.
Reply with quote


damix

Posted: Mon Aug 13, 2012 10:38 pm
Joined: 07 Dec 2011
Posts: 21
Hello CallMeMisterX,

if your problem is finding the center top vertex, I think you can safely assume it is always vertex at index 1. I tried with various cylinders, with odd and even sides and it always selected the top vertex in the center of the triangle fan. If you are interested in the center bottom vertex, use index 0 in place of 1.

Code:

import bpy

bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
mesh = bpy.data.objects['Cylinder'].data
mesh.vertices[1].co.z += 0.25


If you actually want to select vertices, here I have some code adapted from
http://blenderartists.org/forum/showthread.php?207542-Selecting-a-face-through-the-API&highlight=ow%20do%20I%20select/deselect%20vertices/edges/faces%20with%20python in order to work on current Blender release 2.63.

Code:

import bpy

o = bpy.data.objects['Cylinder']
bpy.context.scene.objects.active = o
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
bpy.ops.mesh.select_all(action='DESELECT')

sel_mode = bpy.context.tool_settings.mesh_select_mode
bpy.context.tool_settings.mesh_select_mode = [True, False, False]
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

mesh = o.data
mesh.vertices[1].select = True
   
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
bpy.context.tool_settings.mesh_select_mode = sel_mode
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group