# encoding: UTF-8
# rdz — 현재 부재 실측 (읽기 전용)
MM = 25.4
m = Sketchup.active_model
out = []
def bx(g, tr = nil)
  b = g.bounds
  bb = Geom::BoundingBox.new
  if tr
    [b.min, b.max].each { |p| bb.add(p.transform(tr)) }
  else
    bb.add(b.min); bb.add(b.max)
  end
  [(bb.min.x*25.4).round(2), (bb.min.y*25.4).round(2), (bb.min.z*25.4).round(2), (bb.max.x*25.4).round(2), (bb.max.y*25.4).round(2), (bb.max.z*25.4).round(2)]
end
g2 = m.entities.grep(Sketchup::Group).find { |g| g.definition.name == "그룹#2" }
["사이드막음판_9T_A_20260919", "사이드막음판_9T_B_20260919", "SWD_02_jog30_6T_20260919", "SWD_03_jog20_6T_20260919", "조립부원판_20260919"].each do |nm|
  g = m.entities.grep(Sketchup::Group).find { |x| x.name == nm }
  if g
    v = bx(g)
    out << "#{nm}: x #{v[0]}..#{v[3]} (#{(v[3]-v[0]).round(2)}) y #{v[1]}..#{v[4]} (#{(v[4]-v[1]).round(2)}) z #{v[2]}..#{v[5]} (#{(v[5]-v[2]).round(2)}) solid=#{g.manifold? rescue '?'}"
  else
    out << "#{nm}: 없음"
  end
end
s04 = g2.entities.grep(Sketchup::Group).find { |g| g.name == "SWD_04_t9_240x1046" }
v = bx(s04, g2.transformation)
out << "SWD_04(주황): x #{v[0]}..#{v[3]} y #{v[1]}..#{v[4]} z #{v[2]}..#{v[5]}"
# 주황판 위쪽 간섭 후보
ups = m.entities.to_a.select { |e| (e.is_a?(Sketchup::Group)||e.is_a?(Sketchup::ComponentInstance)) }
      .select { |e| b = e.bounds; !(b.max.x*25.4 < 8700 || b.min.x*25.4 > 9400 || b.max.y*25.4 < 10600 || b.min.y*25.4 > 12100) }
out << "구역 개체: #{ups.map { |e| n = e.name.to_s.empty? ? e.definition.name : e.name; "#{n}[z #{(e.bounds.min.z*25.4).round(1)}..#{(e.bounds.max.z*25.4).round(1)}]" }.inspect}"
puts out.join("\n")
"RDZ"
