Message 1 of 13
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey Experts, what can I do?
I've adapted a code from here:
Gelöst: Re: Auto-detect View Overlap on IDW - Autodesk Community - Inventor
Only for isometric views the code fails at the following line:
oMinDist = oMT.GetMinimumDistance(CurveSegment, bCurveSegment)
getMinimumdistance measures 0 even if the drawing curves don't overlap.
Is there an alternativ way to detect if drawing curves overlap?
Is there an alternativ way to measure the minimum distance of drawing curves?
Sub Main() Dim oDoc As Document = ThisApplication.ActiveDocument If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub On Error resume next Dim oSheet As Sheet = oDoc.ActiveSheet Dim oTG As TransientGeometry = ThisApplication.TransientGeometry For Each AView As DrawingView In oSheet.DrawingViews Dim SP1 As Point2d = AView.Position SP1 = oTG.CreatePoint2d(SP1.X - (AView.Width * 0.5), SP1.Y - (AView.Height * 0.5)) Dim EP1 As Point2d = oTG.CreatePoint2d(SP1.X + AView.Width, SP1.Y + AView.Height) For Each BView As DrawingView In oSheet.DrawingViews If AView Is BView Then Continue For If CheckCH(AView.Name, BView.Name) Then Continue For AddCH(AView.Name, BView.Name) Dim SP2 As Point2d = BView.Position SP2 = oTG.CreatePoint2d(SP2.X - (BView.Width * 0.5), SP2.Y - (BView.Height * 0.5)) Dim EP2 As Point2d = oTG.CreatePoint2d(SP2.X + BView.Width, SP2.Y + BView.Height) Dim DoOverlap As Boolean = CalcOverlap(SP1, EP1, SP2, EP2) If DoOverlap Then Dim oMT As MeasureTools = ThisApplication.MeasureTools For Each aDrawingCurve As DrawingCurve In AView.DrawingCurves For Each aCurveSegment As DrawingCurveSegment In aDrawingCurve.CurveSegments For Each bDrawingCurve As DrawingCurve In BView.DrawingCurves For Each bCurveSegment As DrawingCurveSegment In bDrawingCurve.CurveSegments oMinDist = oMT.GetMinimumDistance(CurveSegment, bCurveSegment) If oMinDist = 0 Then DoOverlap2 = True GoTo overlapping End If Next Next Next Next End If Next Next Exit Sub overlapping: MsgBox("precise calculation shows an overlap") End Sub Private CH(0,1) As String 'Calculation History, so we don't match two views twice Private Function CalcOverlap(SP1 As Point2d, EP1 As Point2d, SP2 As Point2d, EP2 As Point2d) As Boolean If SP1.X < SP2.X Then 'A is on left If EP1.X < SP2.X Then Return False If EP1.Y > EP2.Y Then 'A is on top If SP1.Y < EP2.Y Then Return True Else If EP1.Y > SP2.Y Then Return True End If Else If EP2.X < SP1.X Then Return False If EP1.Y > EP2.Y Then 'A is on top If SP1.Y < EP2.Y Then Return True Else If EP1.Y > SP2.Y Then Return True End If End If Return False End Function Private Function CheckCH(AName As String, BName As String) As Boolean For i = 0 To CInt((CH.Length / 2)) - 1 If CH(i,0) = AName And CH(i, 1) = BName Then Return True If CH(i,0) = BName And CH(i, 1) = AName Then Return True Next Return False End Function Private Sub AddCH(AName As String, BName As String) Dim i As Integer = CInt((CH.Length / 2)) If CH(i - 1, 0) = vbNullString And CH(i - 1, 0) = vbNullString Then i = i - 1 Else ReDim Preserve CH(i, 1) ' Catch ' End try End If CH(i, 0) = AName CH(i, 1) = BName End Sub
Solved! Go to Solution.