# encoding: UTF-8
m = Sketchup.active_model
MM = 1.0/25.4
def r1(v); (v*25.4).round(1); end
src = m.entities.grep(Sketchup::Group).find{|g| g.definition.name=="그룹#2"}
puts "src found=#{!src.nil?}"
begin
  m.start_operation("정배율 복원체", true)
  if src
    inst = m.entities.add_instance(src.definition, Geom::Transformation.translation(Geom::Point3d.new(6400.0*MM, 7501.6*MM, -129.8*MM)))
    inst.make_unique
    inst.name = "SWD조립체_정배율_20260919"
    b = inst.bounds
    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 "  scale #{inst.transformation.xscale.round(4)}/#{inst.transformation.yscale.round(4)}/#{inst.transformation.zscale.round(4)}"
    puts "  원본(그룹#2) 왜곡배율 #{src.transformation.xscale.round(4)}/#{src.transformation.yscale.round(4)}/#{src.transformation.zscale.round(4)}"
    inst.definition.entities.grep(Sketchup::Group).each{|s| sb=s.bounds
      puts "   부재 #{s.name.inspect} #{((sb.max.x-sb.min.x)*25.4).round(1)}x#{((sb.max.y-sb.min.y)*25.4).round(1)}x#{((sb.max.z-sb.min.z)*25.4).round(1)} solid=#{(s.manifold? rescue '?')}"}
  end
  m.commit_operation
rescue Exception => ex
  m.commit_operation rescue nil
  puts "ERR #{ex.class}: #{ex.message}"
end
root = m.entities.grep(Sketchup::Group).find{|g| g.name=="하부마운트커버_v3_20260919"}
newinst = m.entities.grep(Sketchup::ComponentInstance).find{|c| c.name=="SWD조립체_정배율_20260919"}
m.selection.clear
m.selection.add(root) if root
m.selection.add(newinst) if newinst
m.active_view.zoom(m.selection.to_a)
puts "SEL=#{m.selection.length} MODIFIED=#{m.modified?}"
puts "hidden=#{m.entities.grep(Sketchup::Group).select{|g| g.hidden?}.map{|g| g.name.empty? ? g.definition.name : g.name}.inspect}"
"V3C"
