When separating a mesh in edit mode using P, bpy.ops.mesh.separate(type='SELECTED')
, it will select your vertices and make a new object. You are left with two objects.
However, if you select all of the mesh of one object and use it, you will be left with two objects, of which one of has no vertices in it. I need to select this object "if no vertices are present" and delete it.
Here is why I need to do this. I have one object, say a sphere and then using Vertex Weight Proximity and Vertex Weight Edit on other objects (which are joined with one name), I am able to detect all objects intersecting my sphere. These will leave a vertex group, which I can then link up ⌃ Ctrl + L and separate the objects.
However, if all the objects are selected, then I am faced with the problem of having one object with no vertices. I do hope I am clear enough in my question. I need some help with the python script of deleting the object if there are no vertices.
Here is my initial script to separate the objects.
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.vertex_group_set_active(group='V_Group')
bpy.ops.object.vertex_group_select()
bpy.ops.mesh.select_linked(delimit={'SEAM'})
bpy.ops.mesh.separate(type='SELECTED')
bpy.ops.object.editmode_toggle()