Please put the Targetshape on curvesegment center

Sub w_segmentcenter1()
Dim ram As shape
Dim targetShape As shape
Dim validTargetShapeSelected As Boolean
Dim s As shape
Dim X As Double
Dim Y As Double

validTargetShapeSelected = False

' Select the initial shape
Set ram = ActiveSelection.Shapes.First

Do While Not validTargetShapeSelected
' Get user click coordinates to select target shape
If ActiveDocument.GetUserClick(X, Y, 0, 10, False, cdrCursorSmallcrosshair) Then Exit Sub

' Select shape at the clicked position
Set targetShape = ActivePage.SelectShapesAtPoint(X, Y, False).Shapes.Last

validTargetShapeSelected = True
Loop

' Duplicate and center the target shape to each segment of the initial shape
For i = 1 To ram.curve.SubPaths.Count
For j = 1 To ram.curve.SubPaths(i).Nodes.Count - 1
Set s = targetShape.Duplicate
s.centerX = (ram.curve.SubPaths(i).Nodes(j).PositionX + ram.curve.SubPaths(i).Nodes(j + 1).PositionX) / 2
s.centerY = (ram.curve.SubPaths(i).Nodes(j).PositionY + ram.curve.SubPaths(i).Nodes(j + 1).PositionY) / 2
Next j
Next i
End Sub

Result 

Parents
No Data
Reply
  • This result is correct for the mentioned code

    try using the segment offset to center if you want these two to also be in the center of the segment.

      public void SetCenterSegment(Shape curveShapeShapeRange target)
      {
          Curve curve = curveShape.Curve;
     
          for (int i = 1i <= curve.Segments.Count; i++)
          {
              Segment segment = curve.Segments[i];
              ShapeRange targetDuplicate = target.Duplicate();
              Point midPoint = segment.GetPointAt(0.5);
     
              targetDuplicate.SetPositionEx(cdrReferencePoint.cdrCenter, midPoint.x, midPoint.y);
          }
      }

Children
No Data