1
$\begingroup$

I want to fill out the selection I have. So from the active face I want to select more a lot and deselect the normal selection after every iteration. How often it should use the select more command is not important, since my selection that I give should stop the select more command from selecting to much.

enter image description here

So the script should do this:

  1. From my selection it selects only the active face
  2. Selects More command
  3. Deselects my selection I started with except the active face
  4. Repeat 2. to 3. for x times

I could not do it. I tried it with bmesh but I don't understand how it works.

Here is my code so far:

import bpy

growAmount = 30
obj = bpy.context.active_object
if bpy.context.object.mode == 'EDIT':
    bpy.ops.object.mode_set(mode = 'OBJECT')
    bpy.ops.object.mode_set(mode = 'EDIT')

selectedFaces = []
activeFace = obj.data.polygons[obj.data.polygons.active]

for i in obj.data.polygons:
    if i.select:
        if i.index != activeFace.index:
            selectedFaces.append(i.index)

bpy.ops.object.mode_set(mode = 'OBJECT')
for i in selectedFaces:
    obj.data.polygons[i].select = False

for i in range(growAmount):
    bpy.ops.object.mode_set(mode = 'EDIT')
    bpy.ops.mesh.select_more(use_face_step=False)
    bpy.ops.object.mode_set(mode = 'OBJECT')
    for i in selectedFaces:
        obj.data.polygons[i].select = False

bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.mode_set(mode = 'EDIT')

It works okay but leaves edges selected that I don't want.

$\endgroup$

1 Answer 1

0
$\begingroup$

Not the ideal code solution but it works:

import bpy

growAmount = 30
obj = bpy.context.active_object
if bpy.context.object.mode == 'EDIT':
    bpy.ops.object.mode_set(mode = 'OBJECT')
    bpy.ops.object.mode_set(mode = 'EDIT')

selectedFaces = []
selectedEdges = []

activeFace = obj.data.polygons[obj.data.polygons.active]

for i in obj.data.polygons:
    if i.select:
        if i.index != activeFace.index:
            selectedFaces.append(i.index)

for i in obj.data.edges:
    if obj.data.edges[i.index].select:
        selectedEdges.append(i.index)

bpy.ops.object.mode_set(mode = 'OBJECT')
for i in selectedFaces:
    obj.data.polygons[i].select = False

for i in selectedEdges:
    obj.data.edges[i].select = False

for i in range(growAmount):
    bpy.ops.object.mode_set(mode = 'EDIT')
    bpy.ops.mesh.select_more()
    bpy.ops.object.mode_set(mode = 'OBJECT')
    for i in selectedFaces:
        obj.data.polygons[i].select = False
    for i in selectedEdges:
        obj.data.edges[i].select = False

bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.mode_set(mode = 'EDIT')

bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE')
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .