Hi, I guess you want this for some kind of drawing automation. But let me tell you this, going through every line (and else) in every view and checking against the same in every other view would in some cases take AGES.
So, I'd like to suggest you an alternative. I assume you're checking more drawings at once.
1) Check every drawing for "basic" (bounding box) overlap.
2A) If it is OK, go to next
2B) If it isn't remember it (maybe keep it open in background) and go to next
3) Once all drawings are proceeded, show the "not OK" drawings to the user
4) For each of the shown drawings ask the user for confirmation if the drawings is visually OK
5) If it is not ask for correction
6) Save the drawings
7) Live happily ever after
Here's the code you can use for the bounding box check. I assume you have one sheet per drawing, you can easily change it yourself if not.
Sub Main()
Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
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
MsgBox("Save yourself, there's an overlap present!")
End If
Next
Next
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)
End If
CH(i, 0) = AName
CH(i, 1) = BName
End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods