# encoding: UTF-8
m = Sketchup.active_model
def r1(v); (v*25.4).round(1); end
sel = m.selection
puts "SEL COUNT=#{sel.length}"
sel.each do |e|
  nm = e.respond_to?(:name) ? e.name.to_s : ""
  nm = e.definition.name.to_s if nm.empty? && e.respond_to?(:definition)
  puts "SEL: #{e.class} #{nm.inspect}"
  next unless e.respond_to?(:transformation)
  b=e.bounds; t=e.transformation
  puts "  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)})"
  puts "  to_a=#{t.to_a.map{|v| v.round(5)}.inspect}"
  puts "  scale #{t.xscale.round(5)}/#{t.yscale.round(5)}/#{t.zscale.round(5)} det=#{((t.xaxis.cross(t.yaxis)) % t.zaxis).round(5)}"
end
puts "== 그룹#2 (CEO 원본 SWD) 현재 상태 =="
g2 = m.entities.grep(Sketchup::Group).find{|g| g.definition.name=="그룹#2"}
if g2
  b=g2.bounds; t=g2.transformation
  puts "  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)})"
  puts "  to_a=#{t.to_a.map{|v| v.round(5)}.inspect}"
  puts "  xaxis=#{[t.xaxis.x.round(4),t.xaxis.y.round(4),t.xaxis.z.round(4)].inspect}"
  puts "  yaxis=#{[t.yaxis.x.round(4),t.yaxis.y.round(4),t.yaxis.z.round(4)].inspect}"
  puts "  zaxis=#{[t.zaxis.x.round(4),t.zaxis.y.round(4),t.zaxis.z.round(4)].inspect}"
  puts "  det(우수/좌수)=#{((t.xaxis.cross(t.yaxis)) % t.zaxis).round(5)}"
end
puts "== 정배율 복원체 =="
ci = m.entities.grep(Sketchup::ComponentInstance).find{|c| c.name=="SWD조립체_정배율_20260919"}
if ci
  b=ci.bounds; t=ci.transformation
  puts "  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)})"
  puts "  zaxis=#{[t.zaxis.x.round(4),t.zaxis.y.round(4),t.zaxis.z.round(4)].inspect}"
end
"RD4"
