4
$\begingroup$

I use cursor depth to snap the 3d cursor on my object. I want select the face corresponding the 3d cursor. There is a tricks with Blender python API ?

Exemple (Before/After) :

enter image description here enter image description here

| improve this question | | | | |
$\endgroup$
5
$\begingroup$

enter image description here Try this (requires you to have one selected and active mesh object):

import bpy

cur = bpy.context.scene.cursor_location
o   = bpy.context.object

bpy.ops.object.mode_set( mode = 'OBJECT' )
faceIdx = o.closest_point_on_mesh( cur )[-1]

if faceIdx != -1:
    o.data.polygons[ faceIdx ].select = True

bpy.ops.object.mode_set( mode = 'EDIT' )
| improve this answer | | | | |
$\endgroup$
0
$\begingroup$

AFAIK you cannot select a face with the 3D cursor, but Shift+S > Cursor to selected will put it at the center of the face or face group... I think this is what you're asking. Also Shift+S has other settings for direct placement in relation to 3D cursor. they are named

  • Cursor to grid
  • Cursor to center (origin)

they do exactly what they sound like.

| improve this answer | | | | |
$\endgroup$
  • $\begingroup$ I know these shortcuts. This is not what I want. I will see bpy_extras.view3d_utils.location_3d_to_region_2d(region, rv3d, coord) $\endgroup$ – LukeNukem Apr 13 '16 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.