Get/Set entity tag programmatically

Add an attribute to each entity which contains its layer.name [tag],
then explode the container group, using exploded_entities=group.explode
Iterate through exploded_entities, get the attribute from each entity and reapply the layer [by name] to that entity

To set the attribute use something like, on each entity in turn:
entity.set_attribute("Johno3535", "entity_tag", entity.layer.name)

Later on, after the explode… iterate the exploded_entities:
entity.layer=Sketchup.active_model.layers[entity.get_attribute("Johno3535", "entity_tag", "Layer0")]