This code is not exhaustively tested, but it should give you enough ideas:
model = Sketchup.active_model
model.start_operation('Unglue', true)
insts = model.selection.grep(Sketchup;;ComponentInstance)
insts.each{|inst|
inst.glued_to= nil
}
model.commit_operation
One step undo-able...
It un-glues all selected component-instances.