2
$\begingroup$

I have a grid of objects like this: enter image description here

Each object is made of 2 separate meshes (red and blue). Is there a way to use python to delete only the red part and then move the blue part to the front? The red parts' vertices are all Y coordinate 7.5 or bellow so I was wondering if that could be used to select and delete them. The remaining geometry has to be moved -15 along the Y axis afterwards

I can put all the objects in a collection with a specific name or select them manually before hand if that helps make it simpler

$\endgroup$
2
  • $\begingroup$ may i ask how you made the "grid of objects"? or can u provide a blend file, so we can be sure that our code works for u? $\endgroup$
    – Chris
    May 15 at 10:55
  • $\begingroup$ The grid is made by merging the blue objects of 1 grid into the red objects of the grid in front. All the objects origins are at Y=0 and arranged in a 15x15 grid. So (0,0,0), (15,0,0), (0,0,15), (15,0,15), etc. I've added the file to the post $\endgroup$
    – Cornivius
    May 15 at 11:08

1 Answer 1

4
$\begingroup$
   import bpy
   import bmesh

   for object in bpy.context.selected_objects[:]: 
    
    if object.mode == 'OBJECT':
        bm = bmesh.new()
        bm.from_mesh(object.data)
    else:
        bm = bmesh.from_edit_mesh(object.data)


    bm.verts.ensure_lookup_table()
    bm.faces.ensure_lookup_table()

    for vert in bm.verts:
        print(vert.co)
        if vert.co.y <= 7.5:
            bm.verts.remove(vert)
        else:
            vert.co.y += -15

    if object.mode == 'OBJECT':
        bm.to_mesh(object.data)
        bm.free()
    else:
        bmesh.update_edit_mesh(object.data)
  1. select all objects which should be affected
  2. run the code
$\endgroup$
2
  • $\begingroup$ Thanks a lot, it works great $\endgroup$
    – Cornivius
    May 15 at 11:28
  • $\begingroup$ you are welcome $\endgroup$
    – Chris
    May 15 at 11:34

You must log in to answer this question.

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