Distance measure script

Hi!

Could I have some guidance for creating a macro, that allows me to select objects such as in the above picture and measure

and show the distance between the middle point of the first object (different shape than the rest) and the middle point of rest of the objects.

I mean, if I select all of the above objects and click the macro, it then measures and shows the distance between all the circles and the line.

Parents
No Data
Reply
  • Sub Macro1()
         Dim s As Shape, s1 As Shape, SR As ShapeRange
         Dim Dist As Double

         'First, select all shapes except the far left one
         'Then, holding Shift, select the left shape (to be sure it will be =s=). see below

         Set SR = ActiveSelectionRange 'Set range of shapes
         Set s = SR.Shapes.First 'Set s shape
         s.RemoveFromSelection 'Remove s From Selection

         Set SR = ActiveSelectionRange 'ReSet range without s
         For Each s1 In SR 'Calculate distance from Center to Center of shapes pair (X and Y)
              Dist = Sqr(Abs(s1.CenterX - s.CenterX) ^ 2 + Abs(s1.CenterY - s.CenterY) ^ 2)
              Debug.Print Round(Dist, 3), Dist 'Display result in Immediate Window (Ctrl+G)
         Next s1
         'For each shape BoundingBox in Corel you can get such coordinates for:
         ' s.LeftX, s.CenterX, s.RightX
         ' s.TopY, s.CenterY, s.BottomY
         ' and also
         ' s.SizeWidth, s.SizeHeight
    End Sub

Children
No Data