Message 1 of 4
Help: Auto Zoom to Interference Points
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
It's same zoom function after using "Analyze Interference"
Thank you very much!