AverageDistance.bas 878 B

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