(this thread is consequent to https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/auto-detect-view-overlap-on-idw/td-p...)
Recently I've heard about a Rectangle struct with Intersect Method (https://learn.microsoft.com/en-us/dotnet/api/system.drawing.rectangle.intersect?view=net-7.0)
With that knowledge I tried to find Rectangle resulting as overlap of two drawing view boundaries at Sheet #4 of "Inkjet Printer Prototype.idw" (a part of samples kit Inkjet_Printer_Prototype.zip for Inventor 2019 available at https://www.autodesk.com/support/technical/article/caas/tsarticles/ts/3gnm93P9sPAWE6vndk7fjq.html).
I've used this iLogic code:
Option Explicit On
AddReference "System.Drawing.dll"
Imports System.Drawing
Class DrawingViewOverlap
Dim oSheet4 As Sheet
Sub Main
Dim IsIntersecting As Boolean = 0
oSheet4 = ThisDoc.Document.Sheets(4)
Dim InitDrwViews(4-1) As DrawingView
Dim x As Integer = 0
For each oDV in oSheet4.DrawingViews
If oDV.ViewType <> DrawingViewTypeEnum.kDraftDrawingViewType
InitDrwViews(x) = oDV
x +=1
End If
Next
For i = 0 to InitDrwViews.Length - 2
For j = i + 1 to InitDrwViews.Length - 1
Dim oDV1 As DrawingView = InitDrwViews(i)
Dim oDV2 As DrawingView = InitDrwViews(j)
logger.info(oDV1.Label.Text & " -vs- " & oDV2.Label.Text)
Dim oRect1 As New Rectangle(oDV1.Left, oDV1.Top, oDV1.Width, oDV1.Height)
Dim oRect2 As New Rectangle(oDV2.Left, oDV2.Top, oDV2.Width, oDV2.Height)
If TwoRectsOverlap(oRect1, oRect2) Then
IsIntersecting = 1
logger.info(" Intersection is found !!!")
EXIT FOR
End If
Next
If IsIntersecting Then EXIT FOR
Next
End Sub
Function TwoRectsOverlap(oRect1 As Rectangle, oRect2 As Rectangle) As Boolean
Dim oRegion As New Region(oRect1)
Dim oIntersect As Rectangle = Rectangle.Intersect(oRect1, oRect2)
If Not oIntersect.IsEmpty
DrawRect(oRect1)
DrawRect(oRect2)
DrawRect(oIntersect)
End If
Return If(oIntersect.IsEmpty, False, True)
End Function
As a result I've got somewhat close but not exactly what was expected (see Height of the Red Rectangle):
I'd like to know if there any mistake in my code or it is some issue on the Autodesk/Microsoft's side?
PS:
I'm using Inventor 2023.2.1.