Slothole centermark or lines with ilogic

Slothole centermark or lines with ilogic

Tom_BeyerFMVHA
Contributor Contributor
105 Views
2 Replies
Message 1 of 3

Slothole centermark or lines with ilogic

Tom_BeyerFMVHA
Contributor
Contributor

Hello dear community,

 

I am trying to add centre lines or centre marks in the middle of a slot hole. I have tested various code variants, but I am not getting a usable result. I think the best way is to find the semicircle and the two lines of each slot hole (I have created this control function in the following code), and now the problem: I am not getting a point in the centre of the slotted hole.

I tried using the ‘symmetrical centre line’, but I have no idea how to call it between the two lines and semicircles with ilogic.

 

Many thanks in advice

 

Imports Inventor
Imports System.Windows.Forms
Imports System.Math

Sub Main()
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document

Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

Dim oView As DrawingView

For y = 1 To oSheet.DrawingViews.Count
oView = oSheet.DrawingViews.Item(y)

' Isometrische Ansichten überspringen
If oView.Camera.ViewOrientationType = ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation Or _
oView.Camera.ViewOrientationType = ViewOrientationTypeEnum.kIsoBottomRightViewOrientation Or _
oView.Camera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopLeftViewOrientation Or _
oView.Camera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation Then GoTo NextView

Dim oCenterMarks As Centermarks = oSheet.Centermarks
Dim oCurves As DrawingCurvesEnumerator = oView.DrawingCurves

' Liste für Halbkreise sammeln
Dim arcCenters As New List(Of Point2d)

For i = 1 To oCurves.Count
Dim oCurve As DrawingCurve = oCurves.Item(i)

Dim geomType As Curve2dTypeEnum
Try
geomType = oCurve.Segments(1).GeometryType
Catch
GoTo NextCurve
End Try

' Vollkreise -> sofort Centermark
If geomType = Curve2dTypeEnum.kCircleCurve2d Then
AddCentermarkIfNotExists(oCenterMarks, oCurve, oSheet)

' Halbkreise -> für Langloch-Erkennung sammeln
ElseIf geomType = Curve2dTypeEnum.kCircularArcCurve2d Then
Dim arc As Arc2d = oCurve.Segments(1).Geometry
If Abs(arc.SweepAngle) > (PI - (PI / 180)) And _
Abs(arc.SweepAngle) < (PI + (PI / 180)) Then
arcCenters.Add(arc.Center)
End If
End If

NextCurve:
Next

' Halbkreise paarweise auswerten -> Mittelpunkt des Langlochs
If arcCenters.Count >= 2 Then
Dim used As New HashSet(Of Integer)
For i = 0 To arcCenters.Count - 2
If used.Contains(i) Then Continue For
For j = i + 1 To arcCenters.Count - 1
If used.Contains(j) Then Continue For

' Prüfen: gleicher Radius -> plausibles Paar
Dim dist As Double = arcCenters(i).DistanceTo(arcCenters(j))
If dist > 0.0001 Then
' Mittelpunkt berechnen
Dim midX As Double = (arcCenters(i).X + arcCenters(j).X) / 2
Dim midY As Double = (arcCenters(i).Y + arcCenters(j).Y) / 2
Dim midPt As Point2d = oSheet.Parent.TransientGeometry.CreatePoint2d(midX, midY)

AddCentermarkAtPoint(oCenterMarks, midPt, oSheet)

used.Add(i)
used.Add(j)
Exit For
End If
Next
Next
End If

NextView:
Next
End Sub

Private Sub AddCentermarkIfNotExists(oCenterMarks As Centermarks, oCurve As DrawingCurve, oSheet As Sheet)
Try
Dim oDim = oCenterMarks.Add(oSheet.CreateGeometryIntent(oCurve))
RemoveDuplicateCentermarks(oDim, oSheet)
Catch
End Try
End Sub

Private Sub AddCentermarkAtPoint(oCenterMarks As Centermarks, pt As Point2d, oSheet As Sheet)
Try
Dim oIntent As GeometryIntent = oSheet.CreateGeometryIntent(pt)
Dim oDim = oCenterMarks.Add(oIntent)
RemoveDuplicateCentermarks(oDim, oSheet)
Catch
End Try
End Sub

Private Sub RemoveDuplicateCentermarks(oDim As Centermark, oSheet As Sheet)
For j = 1 To oSheet.Centermarks.Count - 1
If Left(oSheet.Centermarks(j).Position.X, 10) = Left(oDim.Position.X, 10) And _
Left(oSheet.Centermarks(j).Position.Y, 10) = Left(oDim.Position.Y, 10) Then
oDim.Delete
Exit For
End If
Next
End Sub

0 Likes
106 Views
2 Replies
Replies (2)
Message 2 of 3

steveh3
Advisor
Advisor

FYI...you might want to join the Inventor Feedback community to see what might be coming. May save you a bit of coding???? 

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 3 of 3

Tom_BeyerFMVHA
Contributor
Contributor

Hi Steve, thats a good idea, thanks for the hint.

0 Likes