Auto-detect View Overlap on IDW

Auto-detect View Overlap on IDW

Maxim-CADman77
Advisor Advisor
2,934 Views
21 Replies
Message 1 of 22

Auto-detect View Overlap on IDW

Maxim-CADman77
Advisor
Advisor

Can anyone share optimal algorithm for smart detecting View Overlap on IDW.

 

I guess firstly View Bounding Box need to be checked for overlapping (How?) .

Next (if Box overlapping is true) re-check to find real overlapping (point that belongs to visible objects of two different views). Again How?

 

My best expectation - detect View with real distance (between visible objects) less then given (let say 10mm).

 

Maybe there is some example of solving alike task with Inventor API shared already?

 

PS: I'm not happy with dumb "Overlapping Views" check that is built into Inventor Design Checker Free App (for subscribers) thus want to replace it with custom iLogic check.

Please vote for Inventor-Idea Text Search within Option Names

Accepted solutions (1)
2,935 Views
21 Replies
Replies (21)
Message 2 of 22

ekinsb
Alumni
Alumni

I don't see an easy, or event a hard solution to this.  What you described is checking to see if any of the geometry from one view overlaps and is a minimum distance from the geometry in another view.  If the red and green shapes shown below represent two different drawing views would you consider them overlapping?

OverlapViews.png

 

 

 

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 22

NachoShaw
Advisor
Advisor

Hi

 

You 'could' do it with math but I'm not sure about a physical check. With math, you could take the center of a view along with the height and width. Then you would need to loop each other view and by calculation, you could work out if one is overlapping the other.

 

Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 4 of 22

Maxim-CADman77
Advisor
Advisor

No (there is no point with same coords on green and red objects thus no overlapping).

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 5 of 22

Maxim-CADman77
Advisor
Advisor
Please, sample of finding line intersection via API Anybody?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 6 of 22

Owner2229
Advisor
Advisor
Accepted solution

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
Message 7 of 22

Maxim-CADman77
Advisor
Advisor
BTW, I'm customer with active subscribtion.
I've submitted Request for Answer on 03/07/2017 and yet there is no Case open foer this issue. Is it normal?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 8 of 22

Owner2229
Advisor
Advisor

Well, yea it is.

(IMO) This forum serves as additional help for those willing to learn. If you want "direct" support, you'll have to contact your reseller. (And even they might want to charge you for it. Depends on your contract).

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
0 Likes
Message 9 of 22

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi MaximUdod,

 

 

In a drawing view, there are many drawing entities involved like BOM table, Drawing dimension, Text labels, leader, balloons etc. These drawing entities are associated with drawing views. In order to develop algorithm for , need to consider these drawing entities.

 

It is very difficult to develop optimal algorithm after considering drawing entities.

 

A simple algorithm to overlap between drawing views is explained below.

 

  1. Read the DrawingView.Position, DrawingView.Height and DrawingView.Width through API.
  2. With these values, a boundary is formed.
  3. Similarly create boundary for all views
  4. After comparing the boundary points, overlap can be detected.

The sample code suggested by @

 looks nice algorithm.

 

Thanks and regards,

 

 

 

 

CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 10 of 22

NachoShaw
Advisor
Advisor

Hi

 

Quote

  1. Read the DrawingView.Position, DrawingView.Height and DrawingView.Width through API.
  2. With these values, a boundary is formed.
  3. Similarly create boundary for all views
  4. After comparing the boundary points, overlap can be detected.

 

Just like what I said early on. I wrote a function for a Solidworks application that checks for overlaps and move the views to have a gap between. It doesn't that long (2-3 seconds max) to process.

 

I'll post it on Monday night. You will need to remove the SW references and replace them with Inventor ones

 

 

 

Cheers

 

Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


Message 11 of 22

Owner2229
Advisor
Advisor

Well, just like the code I posted?

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
0 Likes
Message 12 of 22

Maxim-CADman77
Advisor
Advisor

Two details noted:

1. Your code does not take to a count sketch views.

2. View bounding box has nothing to do with area hihglighted when view is choosen (seems area=view bounding + ?margins?).

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 13 of 22

Maxim-CADman77
Advisor
Advisor

Any ideas on how to check if any end- (middle-) points of lines in Layer "Visible" are present in the particular rectangular area (area of overlapping bounding boxes of the two views)?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 14 of 22

NachoShaw
Advisor
Advisor
Your original all post did not mention mid points of lines on layers in views. You should start a new thread for that.

Also

You shouldn't really have large sketches on your sheets. The sketches are really there to help you with your model views

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 15 of 22

Maxim-CADman77
Advisor
Advisor
"sketches are really there to help you with your model views"
Is it a statement from any official paper?

I believe some 2D-drawings could have no relation to 3D-models.

Mid- and End- points are my new ideas on how the initial goal could be achieved.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 16 of 22

NachoShaw
Advisor
Advisor
No, it's a statement from experience of parametric modelling and notation...

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 17 of 22

SevInventor
Advocate
Advocate

@Owner2229 great solution! Thanks for posting this.

It would be great to even check if the views overlap with the border, title block , part list and sketch symbols

 

0 Likes
Message 18 of 22

SevInventor
Advocate
Advocate

Hi, 

Edit: it doesn't always work properly. See below posts.

I want to share a modified version of Owner2229s Solution for everyone who is searching for 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 Only do this if  

CalcOverlap is True

I think it's fast enough and solves this topic:

SevInventor_0-1685087733914.png

 

:

 

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

I still don't understand the Error at ReDim Preserve CH(i, 1) but whit On Error resume next it works fine for me.

 

like it or not...

0 Likes
Message 19 of 22

Maxim-CADman77
Advisor
Advisor

@SevInventor 

FYI, the code you shared fails (reports an overlap between "Cavity Side" and "VIEW5") in "Switch Mold.idw" (one of the two Mold Designs of a "Legacy Sample Files" kit):

Pseudo-Overlap.png

 

PS:

As for processing object pairs in a collection in the Each-to-Each manner ... you don't need to log any History, instead you can cycle through the collection in a smarter way, like:

 

 

Dim DVcount As Integer = 4

Dim uniqueDVpairCount As Integer = 0
For i = 1 To DVcount - 1 ' oSheet.DrawingViews.Count-1
	For j = i + 1 To DVcount ' oSheet.DrawingViews.Count-1
		uniqueDVpairCount +=1
	Next
Next

logger.info(uniqueDVpairCount)

 

 

 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 20 of 22

SevInventor
Advocate
Advocate

Yes, i can reproduce the same situation, but why should 

ThisApplication.MeasureTools.GetMinimumDistance(CurveSegment, bCurveSegment)

measure 0 if the curve segments don't touch?

Maybe hidden drawing curves?

0 Likes