1
$\begingroup$

The aim is to select the vertices of one side of a cube.

My intention was to change the view's orientation using bpy.ops.view3d.viewnumpad and then select the vertices that are visible, using bpy.ops.vew3d.select_border.

    def changeView(view):
               for area in bpy.context.screen.areas:
                 if area.type == 'VIEW_3D':
                     override = bpy.context.copy()
                     override['area'] = area
                     bpy.ops.view3d.viewnumpad(override, type=view, align_active=False)
                  break   



    def select_border(mesh,context, view3dAreaAndRegion=None, extend=True):
          if not view3dAreaAndRegion:
            view3dAreaAndRegion = getView3dAreaAndRegion(context)
          view3dArea, view3dRegion = view3dAreaAndRegion

          override = context.copy()
          override['area'] = view3dArea
          override['region'] = view3dRegion

          #change orientation to Front side
          changeView('FRONT');

          bpy.ops.view3d.select_border(override,
                                       gesture_mode=3,
                                       xmin=0,
                                       xmax=view3dArea.width,
                                       ymin=0,
                                       ymax=view3dArea.height,
                                       extend=extend)
           return view3dAreaAndRegion

This works, so long as I click 'Run Script' twice, or if the View is already set manually by hitting 1 on the number pad.

However the problem is, if I pan around,then hit 'Run Script' once, it selects all the vertices that are visible from that angle, before changing the view's orientation to Front.

$\endgroup$
2
  • $\begingroup$ If using predefined options, you can try Select > Side Of Active and set up its options (Axis of selection, Positive/Negative etc) or Shift+G > Co-Planar (in face selection mode), it might be similar to your needs. $\endgroup$ – Mr Zak Jan 8 '18 at 21:06
  • $\begingroup$ Comparing face normal to views' normal could be another way to do this without operators. Also Related $\endgroup$ – batFINGER Jan 9 '18 at 5:21
3
$\begingroup$

You could use some vector math to select the right facing verts (deselect all verts and run this in object mode in the text editor, or paste in the console)

from bpy import context as C
from mathutils import Vector

for v in (v for v in C.object.data.vertices if v.normal.dot(Vector((1,0,0))) > 0):
    v.select = True

alternately, to select the left side, change the Vector to (-1,0,0). Top, (0,0,1) etc.

$\endgroup$
0

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.