object EDIT mode/how set: vertex, edge, or face select mode

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

wretch1958
Posts: 22
Joined: Thu Mar 29, 2012 6:26 am

object EDIT mode/how set: vertex, edge, or face select mode

Postby wretch1958 » Thu Mar 29, 2012 6:54 am

bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='EDIT')
The above API commands allow me to switch between OBJECT and EDIT modes. Once I am in EDIT mode, is there a Python command to specify or switch between Vertex Select Mode, Edge Select Mode, and Face Select Mode?????
My goal is to merge certain vertices by doing this:
current_obj.data.vertices[0].select = True
current_obj.data.vertices[1].select = True
bpy.ops.mesh.merge(type='CENTER', uvs=False)
But if the context in EDIT mode is anything other than vertex select mode, in my case it is usually in face select mode) then setting vertices[n] = True does not work. So I need to set context to vertex selection mode with a Python command.

By the way, why do I have to be in OBJECT mode to select vertices (but prior to this, while in EDIT mode, set vertex selection mode), then go back in EDIT mode to merge them. This seems counterintuitive and a lot of jumping back and forth when it really all should happen in EDIT mode?

Thanks ahead of time for any help!

ldo
Posts: 544
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand

Postby ldo » Sun Apr 01, 2012 3:02 am

Code: Select all

context.tool_settings.mesh_select_mode = (vertex, edge, face)


where each of vertex, edge and face is True or False to enable or disable the corresponding selection mode.

wretch1958
Posts: 22
Joined: Thu Mar 29, 2012 6:26 am

Postby wretch1958 » Thu Apr 05, 2012 12:44 am

Thank you 'ldo', that works great.

SpAiK
Posts: 7
Joined: Sat Sep 27, 2008 12:34 pm
Location: Euskadi

Postby SpAiK » Fri Sep 21, 2012 5:11 pm

ldo wrote:

Code: Select all

context.tool_settings.mesh_select_mode = (vertex, edge, face)


where each of vertex, edge and face is True or False to enable or disable the corresponding selection mode.


Hi, I'm looking for a way to assign that to hotkeys, so for example I could change between vertex, edge or face edit modes with 1, 2, 3 keyboard keys. Is that possible?

dustractor
Posts: 15
Joined: Mon Dec 10, 2007 1:52 am
Location: arkansas

hotkeys

Postby dustractor » Fri Sep 21, 2012 10:44 pm

If you don't mind a combo... [Ctrl]+[Tab] then hit [1], [2], or [3] while in edit mode, for vert,edge,face, respectively.

Most of the menu items respond to numeric keys according to their index on the menu -- for example: [shift] + [s] brings up the menu for 3d-cursor-type-stuff, since the fourth thing is cursor to center, so [shift] + [s] , [4] is the shortcut to set the cursor to the origin.


Although I must admit, I have thought about how nice it would be to have single-key shortcuts for the v e and f modes. I just never bothered to write a script.

SpAiK
Posts: 7
Joined: Sat Sep 27, 2008 12:34 pm
Location: Euskadi

Postby SpAiK » Mon Sep 24, 2012 11:12 am

I was using the combo but I realized it was a bit tedious to have use three keys for that instead of using only one, what would be faster.

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Mon Sep 24, 2012 6:43 pm

you can, see here:
http://cgcookie.com/blender/2010/05/17/custom-hot-keys/

basically add hotkeys,
operator: wm.context_set_value
data path: tool_settings.mesh_select_mode
value: False, True, False (for edge mode)
I'm sitting, waiting, wishing, building Blender in superstition...

SpAiK
Posts: 7
Joined: Sat Sep 27, 2008 12:34 pm
Location: Euskadi

Postby SpAiK » Mon Sep 24, 2012 8:28 pm

CoDEmanX wrote:you can, see here:
http://cgcookie.com/blender/2010/05/17/custom-hot-keys/

basically add hotkeys,
operator: wm.context_set_value
data path: tool_settings.mesh_select_mode
value: False, True, False (for edge mode)


Thank you so much! This is what I was looking for. I was trying myself to create hotkeys but they weren't working.


Return to “Python”

Who is online

Users browsing this forum: No registered users and 1 guest