0
$\begingroup$

I need a script that deletes all vertices from a group of selected objects. I intend to merge some other objects to them afterwards to effectively copy their names.

I previously asked how to delete only specific vertices below a certain Y coordinate here: Python: Delete vertices by coordinates The solution does work but it takes a pretty long time. I assume bc it has to individually check all the vertices and this are pretty dense meshes. The vertices above the Y coordinate are from objects that get merged into them, so I think that maybe I could just delete all the vertices in the original objects and then merge the other ones without having to worry about coordinates. I assume this would be a lot faster since it only involves selecting everything in edit mode and deleting it.

I've tried modifying the code given in the other question to do what I want but I really don't know what I'm doing when it comes with programming. If anyone can give me a hand that'd be much appreciated.

$\endgroup$
2
  • $\begingroup$ i am not sure whether i understood what you want: you really wanna delete all (!?) vertices from selected objects? that's what you wrote. Then just select all objects, TAB -> edit mode, A -> select all -> x vertices done. $\endgroup$
    – Chris
    Commented May 27 at 7:09
  • $\begingroup$ Yes, but it's part of a larger process where I'm using python to try an automate the whole thing. Atm I'm basically doing just that with a macro and it works fine but it'd be nice if the whole thing could be executed at once instead of having to rely on a mix of activations $\endgroup$
    – Cornivius
    Commented May 27 at 9:54

1 Answer 1

1
$\begingroup$

you can use this script:

import bpy, bmesh

for ob in bpy.context.selected_objects:

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

    me = ob.data
    bm = bmesh.from_edit_mesh(me)

    verts = [v for v in bm.verts]

    bmesh.ops.delete(bm, geom=verts)

    bmesh.update_edit_mesh(me)
    
    
bpy.ops.object.mode_set(mode='OBJECT')

Note: this is NOT a clean script. Normally you should ...

  • ask the ob if it is a mesh object
  • get the current mode, save that and set it to the current mode back again
$\endgroup$
1
  • $\begingroup$ Thanks, that works. Not sure what you mean by clean script but it's always going to be used on mesh objects in obj mode so I don't think it'll be a problem $\endgroup$
    – Cornivius
    Commented May 27 at 21:01

You must log in to answer this question.

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