# encoding: UTF-8
# B의 y가 보라 브라켓(SWD_07 웹 외면 y=11743.54) 대비 +40 어긋나 있어 y만 보정. 형상 무수정.
m = Sketchup.active_model
b = m.entities.grep(Sketchup::Group).find{|g| g.name=='연결브라켓_L_B_20260919'}
a = m.entities.grep(Sketchup::Group).find{|g| g.name=='연결브라켓_L_A_20260919'}
raise "브라켓 없음" if a.nil? || b.nil?
pre_a = a.bounds; pre_b = b.bounds
dy = 11743.54 - pre_b.min.y.to_mm
m.start_operation('B y 정렬', true)
b.transform!(Geom::Transformation.translation(Geom::Vector3d.new(0, dy.mm, 0)))
m.commit_operation
[['A',a,pre_a],['B',b,pre_b]].each do |nm,g,pb|
  nb = g.bounds
  puts "#{nm} 전 x %.2f..%.2f y %.2f..%.2f z %.2f..%.2f" % [pb.min.x.to_mm,pb.max.x.to_mm,pb.min.y.to_mm,pb.max.y.to_mm,pb.min.z.to_mm,pb.max.z.to_mm]
  puts "#{nm} 후 x %.2f..%.2f y %.2f..%.2f z %.2f..%.2f (조각solid=#{g.entities.grep(Sketchup::Group).map{|s| s.manifold?}.inspect})" %
    [nb.min.x.to_mm,nb.max.x.to_mm,nb.min.y.to_mm,nb.max.y.to_mm,nb.min.z.to_mm,nb.max.z.to_mm]
end
puts "B dy=%.2f" % dy
m.save
puts "SAVED #{File.mtime(m.path)}"
nil
