ent.erase_entities inst1
ent.erase_entities inst2
ent.erase_entities inst3
ent.erase_entities inst4
… can be simplified to …
ent.erase_entities( inst1, inst2, inst3, inst4 )
… or …
ent.erase_entities( [inst1, inst2, inst3, inst4] )
ent.erase_entities(
com_def.instances.select {|inst| ent.include?(inst) }
)
… will erase ALL of the definition’s instances that are within the ent entities collection.
But if you just wish to delete ALL of com_def’s instances, no matter what entities collection they are a member of (nested or top level) …
com_def.instances.dup.each {|inst| inst.erase! }
This will preserve com_def in the model’s definition list.
But if you will no longer need com_def, then let SketchUp (2018 or higher) delete all the instances for you …
def_list.remove( com_def )