Sub w_segmentcenter1()Dim ram As shapeDim targetShape As shapeDim validTargetShapeSelected As BooleanDim s As shapeDim X As DoubleDim Y As Double
validTargetShapeSelected = False
' Select the initial shapeSet 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 = TrueLoop
' Duplicate and center the target shape to each segment of the initial shapeFor 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 jNext iEnd SubResult
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 curveShape, ShapeRange target) { Curve curve = curveShape.Curve; for (int i = 1; i <= 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); } }
Perfect sir. Thanking you so much