try this:
Public Class ThisRule
Sub Main()
Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim view As DrawingView = sheet.DrawingViews.Item(1)
Dim rows As New List(Of Row)
For Each curve As DrawingCurve In view.DrawingCurves
If (curve.CurveType = CurveTypeEnum.kCircleCurve) Then
Dim center = curve.CenterPoint
Dim x = center.X
Dim y = center.Y
Dim foundRow = rows.Where(Function(r) Math.Abs(r.Y - y) < 0.0001).FirstOrDefault
If (foundRow Is Nothing) Then
Dim row As New Row(curve)
rows.Add(row)
Else
foundRow.N += 1
If (foundRow.X > x) Then
foundRow.HoleCUrve = curve
End If
End If
End If
Next
Dim orderdRow = rows.OrderBy(Function(r) r.Y)
Dim lineSpacing = 0.75
Dim insertPointX = view.Center.X - view.Width / 2 - 1.5
Dim insertPointY = view.Center.Y - (lineSpacing * orderdRow.Count / 2)
For Each row As Row In orderdRow
logger.Info(Row.N)
Dim leaderPoints = ThisApplication.TransientObjects.CreateObjectCollection()
Dim insertPoint = ThisApplication.TransientGeometry.CreatePoint2d(insertPointX, insertPointY)
Dim curveIntent As GeometryIntent = sheet.CreateGeometryIntent(Row.HoleCUrve)
leaderPoints.Add(insertPoint)
leaderPoints.Add(curveIntent)
sheet.DrawingNotes.LeaderNotes.Add(leaderPoints, String.Format("{0} Holes", Row.N))
insertPointY = insertPointY + lineSpacing
Next
End Sub
End Class
Public Class Row
Public Sub New(holeCUrve As DrawingCurve)
Me.HoleCUrve = holeCUrve
N = 1
Y = holeCUrve.CenterPoint.Y
End Sub
Public Property HoleCUrve As DrawingCurve
Public Property N As Integer
Public Property Y As Double
Public ReadOnly Property X As Double
Get
Return HoleCUrve.CenterPoint.X
End Get
End Property
End Class
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog: hjalte.nl - github.com