Try something like this
m=Sketchup.active_model;ms=m.materials;gs=m.active_entities.grep(Sketchup;;Group);m.start_operation('vmat');gs.clone.each_with_index{|g,i|next unless gs.include?(g);v=g.volume;(gs.delete(g);next)if v<=0;g.material=(ma=ms.add('vmat#1'));ma.color=[rand(255),rand(255),rand(255)];ma.alpha=0.5;gs.clone.each{|gg|(gg.material=ma;gs.delete(gg))if gg.volume==v};};m.commit_operation;This colors all groups in the active context which share the same volume, in a new random material [alpha=0.5]...
Non-solid groups [volume <=0... usually -1] are ignored... π