Help: Auto Zoom to Interference Points

Help: Auto Zoom to Interference Points

ngdnam88
Advocate Advocate
323 Views
3 Replies
Message 1 of 4

Help: Auto Zoom to Interference Points

ngdnam88
Advocate
Advocate

Dears,

I'm using this iLogic from this post to detect interference. 

 

 

https://clintbrown.co.uk/2019/02/03/interference/
On Error GoTo Error1 ' Code adapted from the Inventor API Sample to work with iLogic by Clint Brown
'Code originally posted at https://clintbrown.co.uk/interference
    Dim oDoc As AssemblyDocument
     oDoc = ThisApplication.ActiveDocument
    
    ' Find all selected occurrences and add them to an ObjectCollection.
    Dim oSelectedOccs As ObjectCollection
     oSelectedOccs = ThisApplication.TransientObjects.CreateObjectCollection
    Dim i As Long
'    For i = 1 To oDoc.Select.Count
For i = 1 To oDoc.SelectSet.Count
        If oDoc.Select.Item(i).Type = kComponentOccurrenceObject Then
            oSelectedOccs.Add(oDoc.Select.Item(i))
        End If
    Next
    
 
    Dim oResults As InterferenceResults
    Dim oCheck As ObjectCollection
     oCheck = ThisApplication.TransientObjects.CreateObjectCollection
    If oSelectedOccs.Count = 0 Then
        ' Add all occurrences to the object collection
        Dim oOcc As ComponentOccurrence
        For Each oOcc In oDoc.ComponentDefinition.Occurrences
            oCheck.Add(oOcc)
        Next
        
        ' Get the interference between everything.
         oResults = oDoc.ComponentDefinition.AnalyzeInterference(oCheck)
    ElseIf oSelectedOccs.Count = 1 Then
        ' Add all occurrences except the selected occurrence to the object collection.
        For Each oOcc In oDoc.ComponentDefinition.Occurrences
            If Not oOcc Is oSelectedOccs.Item(1) Then
                oCheck.Add(oOcc)
            End If
        Next
        
        ' Get the interference between the selected occurrence everything else.
         oResults = oDoc.ComponentDefinition.AnalyzeInterference(oSelectedOccs, oCheck)
    Else
        If MsgBox("Check interference between selected occurrences and all other occurrences?", "@ClintBrown3D", vbYesNo + vbQuestion) = vbYes Then
            ' Add all occurrences except the selected occurrences to the object collection.
            For Each oOcc In oDoc.ComponentDefinition.Occurrences
                ' Check to see if this occurrences is already selected.
                Dim bSelected As Boolean
                bSelected = False
                For i = 1 To oSelectedOccs.Count
                    If oSelectedOccs.Item(i) Is oOcc Then
                        bSelected = True
                        Exit For
                    End If
                Next
                
                If Not bSelected Then
                    oCheck.Add(oOcc)
                End If
            Next
           
            ' Check interference between the selected items.
             oResults = oDoc.ComponentDefinition.AnalyzeInterference(oSelectedOccs, oCheck)
        Else
            ' Check interference between the selected items.
             oResults = oDoc.ComponentDefinition.AnalyzeInterference(oSelectedOccs)
        End If
    End If
    
    If oResults.Count = 1 Then
        MsgBox("There is 1 interference.")
    ElseIf oResults.Count > 1 Then
		MessageBox.Show("There are " & oResults.Count & " interferences.", "@ClintBrown3D")
    End If

    If oResults.Count > 0 Then
		Dim oHS1 As HighlightSet
        oHS1 = oDoc.CreateHighlightSet
        oHS1.Color = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
        Dim oHS2 As HighlightSet
         oHS2 = oDoc.CreateHighlightSet
        oHS2.Color = ThisApplication.TransientObjects.CreateColor(0, 255, 0)
        
        For i = 1 To oResults.Count
            oHS1.Clear
            oHS2.Clear
            oHS1.AddItem(oResults.Item(i).OccurrenceOne)
            oHS2.AddItem(oResults.Item(i).OccurrenceTwo)
         	MessageBox.Show("Occurrences are highlighted from interference " & i, "@ClintBrown3D")
        Next
        oHS1.Clear
        oHS2.Clear
    Else
		MessageBox.Show("There is no interference :)", "@ClintBrown3D")
    End If
Return

Error1 :
MessageBox.Show("We ran into a problem, Please ensure that you are in an assembly file, or try the manual Interference Checker", "@ClintBrown3D")

 

 

 

Please help me the code that can Zoom to Each Interference points as this picture

ngnam1988_0-1673282989294.png

It's same zoom function after using "Analyze Interference"

ngnam1988_0-1673283093653.png

Thank you very much!

0 Likes
324 Views
3 Replies
Replies (3)
Message 2 of 4

bradeneuropeArthur
Mentor
Mentor

Use this piece of code:

On Error GoTo Error1 ' Code adapted from the Inventor API Sample to work with iLogic by Clint Brown
'Code originally posted at https://clintbrown.co.uk/interference
    Dim oDoc As AssemblyDocument
     oDoc = ThisApplication.ActiveDocument
    
    ' Find all selected occurrences and add them to an ObjectCollection.
    Dim oSelectedOccs As ObjectCollection
     oSelectedOccs = ThisApplication.TransientObjects.CreateObjectCollection
    Dim i As Long
'    For i = 1 To oDoc.Select.Count
For i = 1 To oDoc.SelectSet.Count
        If oDoc.Select.Item(i).Type = kComponentOccurrenceObject Then
            oSelectedOccs.Add(oDoc.Select.Item(i))
        End If
    Next
    
 
    Dim oResults As InterferenceResults
    Dim oCheck As ObjectCollection
     oCheck = ThisApplication.TransientObjects.CreateObjectCollection
    If oSelectedOccs.Count = 0 Then
        ' Add all occurrences to the object collection
        Dim oOcc As ComponentOccurrence
        For Each oOcc In oDoc.ComponentDefinition.Occurrences
            oCheck.Add(oOcc)
        Next
        
        ' Get the interference between everything.
         oResults = oDoc.ComponentDefinition.AnalyzeInterference(oCheck)
    ElseIf oSelectedOccs.Count = 1 Then
        ' Add all occurrences except the selected occurrence to the object collection.
        For Each oOcc In oDoc.ComponentDefinition.Occurrences
            If Not oOcc Is oSelectedOccs.Item(1) Then
                oCheck.Add(oOcc)
            End If
        Next
        
        ' Get the interference between the selected occurrence everything else.
         oResults = oDoc.ComponentDefinition.AnalyzeInterference(oSelectedOccs, oCheck)
    Else
        If MsgBox("Check interference between selected occurrences and all other occurrences?", "@ClintBrown3D", vbYesNo + vbQuestion) = vbYes Then
            ' Add all occurrences except the selected occurrences to the object collection.
            For Each oOcc In oDoc.ComponentDefinition.Occurrences
                ' Check to see if this occurrences is already selected.
                Dim bSelected As Boolean
                bSelected = False
                For i = 1 To oSelectedOccs.Count
                    If oSelectedOccs.Item(i) Is oOcc Then
                        bSelected = True
                        Exit For
                    End If
                Next
                
                If Not bSelected Then
                    oCheck.Add(oOcc)
                End If
            Next
           
            ' Check interference between the selected items.
             oResults = oDoc.ComponentDefinition.AnalyzeInterference(oSelectedOccs, oCheck)
        Else
            ' Check interference between the selected items.
             oResults = oDoc.ComponentDefinition.AnalyzeInterference(oSelectedOccs)
        End If
    End If
    
    If oResults.Count = 1 Then
        MsgBox("There is 1 interference.")
    ElseIf oResults.Count > 1 Then
		MessageBox.Show("There are" & oResults.Count & " interferences.", "@ClintBrown3D")
		

    End If

'Dim oCamera As Camera
'oCamera = ThisApplication.ActiveView.Camera
' 'MsgBox(oResults.Item.OccurrenceOne)
'   Dim NewTargePnt As Inventor.Point = oResults.Item(1).OccurrenceOne.RangeBox.MinPoint
   
'   NewTargePnt = ThisApplication.TransientGeometry.CreatePoint(NewTargePnt.X, NewTargePnt.Y)
'   oCamera.Target = NewTargePnt

'   Call oCamera.SetExtents(40, 40)

    If oResults.Count > 0 Then
		Dim oHS1 As HighlightSet
        oHS1 = oDoc.CreateHighlightSet
        oHS1.Color = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
        Dim oHS2 As HighlightSet
         oHS2 = oDoc.CreateHighlightSet
        oHS2.Color = ThisApplication.TransientObjects.CreateColor(0, 255, 0)
        
        For i = 1 To oResults.Count
            oHS1.Clear
            oHS2.Clear
            oHS1.AddItem(oResults.Item(i).OccurrenceOne)
            oHS2.AddItem(oResults.Item(i).OccurrenceTwo)
			Dim oCamera As Camera
			oCamera = ThisApplication.ActiveView.Camera
 				'MsgBox(oResults.Item.OccurrenceOne)
   				Dim NewTargePnt As Inventor.Point = oResults.Item(i).OccurrenceOne.RangeBox.MinPoint
   				NewTargePnt = ThisApplication.TransientGeometry.CreatePoint(NewTargePnt.X, NewTargePnt.Y, 0)
   				
   				oCamera.Target = NewTargePnt
   				Call oCamera.SetExtents(10, 10)
   				oCamera.Apply
         	MessageBox.Show("Occurrences are highlighted from interference " & i, "@ClintBrown3D")
        Next
        oHS1.Clear
        oHS2.Clear
    Else
		MessageBox.Show("There is no interference :)", "@ClintBrown3D")
    End If
Return

Error1 :
MessageBox.Show("We ran into a problem, Please ensure that you are in an assembly file, or try the manual Interference Checker", "@ClintBrown3D")

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 3 of 4

JelteDeJong
Mentor
Mentor

probably not as good as the solution of @bradeneuropeArthur but it took me some time to see his solution. So i figured that I could post this solution also.

Dim selctionSet = oDoc.SelectSet
selctionSet.Clear()
selctionSet.Select(oResults.Item(i).OccurrenceOne)
selctionSet.Select(oResults.Item(i).OccurrenceTwo)
ThisApplication.CommandManager.ControlDefinitions.Item("AppZoomSelectCmd").Execute()

Jelte de Jong
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.

EESignature


Blog: hjalte.nl - github.com

Message 4 of 4

bradeneuropeArthur
Mentor
Mentor

 

On Error GoTo Error1 ' Code adapted from the Inventor API Sample to work with iLogic by Clint Brown
'Code originally posted at https://clintbrown.co.uk/interference
    Dim oDoc As AssemblyDocument
     oDoc = ThisApplication.ActiveDocument
    
    ' Find all selected occurrences and add them to an ObjectCollection.
    Dim oSelectedOccs As ObjectCollection
     oSelectedOccs = ThisApplication.TransientObjects.CreateObjectCollection
    Dim i As Long
'    For i = 1 To oDoc.Select.Count
For i = 1 To oDoc.SelectSet.Count
        If oDoc.Select.Item(i).Type = kComponentOccurrenceObject Then
            oSelectedOccs.Add(oDoc.Select.Item(i))
        End If
    Next
    
 
    Dim oResults As InterferenceResults
    Dim oCheck As ObjectCollection
     oCheck = ThisApplication.TransientObjects.CreateObjectCollection
    If oSelectedOccs.Count = 0 Then
        ' Add all occurrences to the object collection
        Dim oOcc As ComponentOccurrence
        For Each oOcc In oDoc.ComponentDefinition.Occurrences
            oCheck.Add(oOcc)
        Next
        
        ' Get the interference between everything.
         oResults = oDoc.ComponentDefinition.AnalyzeInterference(oCheck)
    ElseIf oSelectedOccs.Count = 1 Then
        ' Add all occurrences except the selected occurrence to the object collection.
        For Each oOcc In oDoc.ComponentDefinition.Occurrences
            If Not oOcc Is oSelectedOccs.Item(1) Then
                oCheck.Add(oOcc)
            End If
        Next
        
        ' Get the interference between the selected occurrence everything else.
         oResults = oDoc.ComponentDefinition.AnalyzeInterference(oSelectedOccs, oCheck)
    Else
        If MsgBox("Check interference between selected occurrences and all other occurrences?", "@ClintBrown3D", vbYesNo + vbQuestion) = vbYes Then
            ' Add all occurrences except the selected occurrences to the object collection.
            For Each oOcc In oDoc.ComponentDefinition.Occurrences
                ' Check to see if this occurrences is already selected.
                Dim bSelected As Boolean
                bSelected = False
                For i = 1 To oSelectedOccs.Count
                    If oSelectedOccs.Item(i) Is oOcc Then
                        bSelected = True
                        Exit For
                    End If
                Next
                
                If Not bSelected Then
                    oCheck.Add(oOcc)
                End If
            Next
           
            ' Check interference between the selected items.
             oResults = oDoc.ComponentDefinition.AnalyzeInterference(oSelectedOccs, oCheck)
        Else
            ' Check interference between the selected items.
             oResults = oDoc.ComponentDefinition.AnalyzeInterference(oSelectedOccs)
        End If
    End If
    
    If oResults.Count = 1 Then
        MsgBox("There is 1 interference.")
    ElseIf oResults.Count > 1 Then
		MessageBox.Show("There are" & oResults.Count & " interferences.", "@ClintBrown3D")
		

    End If

    If oResults.Count > 0 Then
		Dim oHS1 As HighlightSet
        oHS1 = oDoc.CreateHighlightSet
        oHS1.Color = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
        Dim oHS2 As HighlightSet
         oHS2 = oDoc.CreateHighlightSet
        oHS2.Color = ThisApplication.TransientObjects.CreateColor(0, 255, 0)
        
        For i = 1 To oResults.Count
            oHS1.Clear
            oHS2.Clear
            oHS1.AddItem(oResults.Item(i).OccurrenceOne)
            oHS2.AddItem(oResults.Item(i).OccurrenceTwo)
			Dim oCamera As Camera
			oCamera = ThisApplication.ActiveView.Camera
 				'MsgBox(oResults.Item.OccurrenceOne)
   				Dim NewTargePnt As Inventor.Point = oResults.Item(i).OccurrenceOne.RangeBox.MinPoint
   				NewTargePnt = ThisApplication.TransientGeometry.CreatePoint(NewTargePnt.X, NewTargePnt.Y, NewTargePnt.Z)
   				
   				oCamera.Target = NewTargePnt
   				Call oCamera.SetExtents(10, 10)
   				oCamera.Apply
         	MessageBox.Show("Occurrences are highlighted from interference " & i, "@ClintBrown3D")
        Next
        oHS1.Clear
        oHS2.Clear
    Else
		MessageBox.Show("There is no interference :)", "@ClintBrown3D")
    End If
Return

Error1 :
MessageBox.Show("We ran into a problem, Please ensure that you are in an assembly file, or try the manual Interference Checker", "@ClintBrown3D")

 

Thanks @JelteDeJong  , appreciated.

I have modified it a bit after cross-check!

 

 

 

 

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature