# 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
# Y로 길게 가로지르는(좌우 횡단) 부재 후보 = Yspan > 1000 이고 Xspan < 400
puts "== 좌우 횡단 후보 (Yspan>1000, Xspan<400) =="
(m.entities.grep(Sketchup::Group) + m.entities.grep(Sketchup::ComponentInstance)).each do |e|
  b = e.bounds
  xs=(b.max.x-b.min.x)*25.4; ys=(b.max.y-b.min.y)*25.4; zs=(b.max.z-b.min.z)*25.4
  next unless ys > 1000 && xs < 400
  nm = e.respond_to?(:definition) ? "#{e.name.empty? ? e.definition.name : e.name}" : e.name
  # 얇은 판 개수로 절곡품 판정
  leafs = 0; e.definition.entities.grep(Sketchup::Face).each{|f| leafs+=1} rescue nil
  puts "  #{nm.inspect}  X=#{xs.round(1)} Y=#{ys.round(1)} Z=#{zs.round(1)}  bbox #{mmv(b.min)}..#{mmv(b.max)} faces=#{leafs}"
end
puts "== G5 상세 (X5456~5616, Y7467~8813, Z41.9~161.9) =="
g5 = m.entities.grep(Sketchup::Group).find{|g| b=g.bounds; (b.min.x*25.4).round(1)==5456.0 }
if g5
  puts "  ents=#{g5.entities.length} scale=#{g5.transformation.xscale.round(4)}/#{g5.transformation.yscale.round(4)}/#{g5.transformation.zscale.round(4)}"
  g5.entities.grep(Sketchup::Group).each{|s| b=s.bounds; puts "   sub #{s.name.inspect} #{mmv(b.min)}..#{mmv(b.max)}"}
  # 판두께 추정: 가장 큰 면들의 법선/면적
  fs = g5.entities.grep(Sketchup::Face).sort_by{|f| -f.area}[0,6]
  fs.each{|f| n=f.normal.transform(g5.transformation); puts "   face #{(f.area*645.16/100).round(1)}cm2 n=(#{n.x.round(3)},#{n.y.round(3)},#{n.z.round(3)})"}
end
"CAND1"
