# encoding: UTF-8
# rd8 — 선택 읽기만 (수정 없음)
def r1(v); (v * 25.4).round(1); end
m = Sketchup.active_model
out = []
sel = m.selection.to_a
out << "SEL COUNT=#{sel.length}"
sel.each_with_index do |e, i|
  nm = (e.respond_to?(:name) ? e.name : "")
  nm = e.definition.name if nm.to_s.empty? && e.respond_to?(:definition)
  out << "[#{i}] #{e.class} #{nm.inspect}"
  if e.respond_to?(:bounds)
    b = e.bounds
    out << "   world bbox (#{r1(b.min.x)},#{r1(b.min.y)},#{r1(b.min.z)})..(#{r1(b.max.x)},#{r1(b.max.y)},#{r1(b.max.z)}) size #{r1(b.width)}x#{r1(b.height)}x#{r1(b.depth)}"
  end
  if e.respond_to?(:entities)
    ents = e.entities
    fs = ents.grep(Sketchup::Face)
    out << "   ents=#{ents.length} faces=#{fs.length} grp=#{ents.grep(Sketchup::Group).length} cmp=#{ents.grep(Sketchup::ComponentInstance).length} solid=#{(e.respond_to?(:manifold?) ? e.manifold? : 'n/a')}"
    lb = ents.parent.bounds
    out << "   로컬 bbox (#{r1(lb.min.x)},#{r1(lb.min.y)},#{r1(lb.min.z)})..(#{r1(lb.max.x)},#{r1(lb.max.y)},#{r1(lb.max.z)})"
    tr = e.transformation.to_a
    out << "   scale #{(Geom::Vector3d.new(tr[0],tr[1],tr[2]).length).round(4)}/#{(Geom::Vector3d.new(tr[4],tr[5],tr[6]).length).round(4)}/#{(Geom::Vector3d.new(tr[8],tr[9],tr[10]).length).round(4)}"
    # 내부 루프(구멍) 목록 — 로컬좌표
    holes = []
    fs.each do |f|
      f.loops.each do |lp|
        next if lp.outer?
        bb = Geom::BoundingBox.new
        lp.vertices.each { |v| bb.add(v.position) }
        holes << [r1(bb.center.x), r1(bb.center.y), r1(bb.center.z), r1([bb.width, bb.height, bb.depth].max)]
      end
    end
    out << "   내부루프(구멍) #{holes.length}개:"
    holes.each { |h| out << "      c=(#{h[0]},#{h[1]},#{h[2]}) d~#{h[3]}" }
  end
  # 부모 정보
  begin
    par = e.parent
    out << "   parent=#{par.class} #{(par.respond_to?(:name) ? par.name : '').inspect}"
  rescue Exception => ex
    out << "   parent 조회 실패 #{ex.class}"
  end
end
puts out.join("\n")
"RD8"
