# encoding: UTF-8
m = Sketchup.active_model
def mmv(p); [(p.x*25.4).round(1),(p.y*25.4).round(1),(p.z*25.4).round(1)]; end

g33 = m.entities.grep(Sketchup::Group).find{|g| b=g.bounds; (b.min.z*25.4).round(1) == -129.8 }
if g33
  t = g33.transformation
  puts "G33 tr xscale=#{t.xscale.round(5)} yscale=#{t.yscale.round(5)} zscale=#{t.zscale.round(5)}"
  puts "G33 to_a=#{t.to_a.map{|v| v.round(5)}.inspect}"
  puts "G33 origin mm=#{mmv(t.origin)}"
end

# existing holes in LH/RH bottom flange region
["RJ102-0604_LH_20260918","RJ102-0602_RH_20260918"].each do |nm|
  g = m.entities.grep(Sketchup::Group).find{|x| x.name==nm}
  next unless g
  tr = g.transformation
  puts "== #{nm} holes (X 3700-4700) =="
  seen = []
  g.entities.grep(Sketchup::Face).each do |f|
    f.loops.each do |lp|
      next if lp.outer?
      c = lp.bounds.center.transform(tr)
      cx = c.x*25.4
      next unless cx > 3700 && cx < 4700
      d = [lp.bounds.width*25.4, lp.bounds.height*25.4, lp.bounds.depth*25.4].sort
      key = mmv(c)
      next if seen.any?{|s| (s[0]-key[0]).abs<1 && (s[1]-key[1]).abs<1 && (s[2]-key[2]).abs<1}
      seen << key
      puts "  hole ctr=#{key} size=#{d.map{|v| v.round(1)}.inspect} edges=#{lp.edges.length}"
    end
  end
  puts "  (none)" if seen.empty?
end
"SURVEY3"
