AverageDistance.bas 940 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. Attribute VB_Name = "AverageDistance"
  2. Public AutoDistribute_Key As Boolean
  3. Public first_StaticID As Long
  4. '// Ñ¡ÔñµÄÎï¼þƽ¾ù¾àÀë
  5. Public Function Average_Distance()
  6. On Error GoTo ErrorHandler
  7. API.BeginOpt
  8. Dim sr As ShapeRange
  9. Set sr = ActiveSelectionRange
  10. sr.Sort "@shape1.left<@shape2.left"
  11. Distribute_Shapes sr
  12. ErrorHandler:
  13. API.EndOpt
  14. End Function
  15. Private Function Distribute_Shapes(sr As ShapeRange)
  16. Dim first As Double, last As Double
  17. Dim interval As Double, currentPoint As Double
  18. Dim total As Integer
  19. Dim sh As Shape
  20. first_StaticID = sr.FirstShape.StaticID
  21. total = sr.Count
  22. first = sr.FirstShape.CenterX
  23. last = sr.LastShape.CenterX
  24. interval = (last - first) / (total - 1)
  25. currentPoint = first
  26. For Each sh In sr
  27. sh.CenterY = sr.FirstShape.CenterY
  28. sh.CenterX = currentPoint
  29. currentPoint = currentPoint + interval
  30. Next sh
  31. End Function