Amount Holes 2D. In Rows.

Amount Holes 2D. In Rows.

iva.btblan
Advocate Advocate
332 Views
2 Replies
Message 1 of 3

Amount Holes 2D. In Rows.

iva.btblan
Advocate
Advocate

After the completion of the study.

I need to indicate the amounts of holes in the 2d.

06.05.0012.png

This indication is necessary to facilitate manufacturing. it's tiring to count all these holes.

0 Likes
Accepted solutions (1)
333 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

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.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 3

iva.btblan
Advocate
Advocate

Wonderful!

thank you for your attention.

Thanks for the help!

0 Likes