Code:
Public Sub Kollisionsanalyse()
If oInventorApp.ActiveDocument Is Nothing Then
MsgBox("Keine Baugruppe geöffnet")
Exit Sub
End If
Dim oAsmDoc As AssemblyDocument
If TypeOf oInventorApp.ActiveDocument Is AssemblyDocument Then
oAsmDoc = oInventorApp.ActiveDocument
Else : MsgBox("Geht nur in Baugruppen")
Exit Sub
End If
Dim oAsmDef As AssemblyComponentDefinition
oAsmDef = oAsmDoc.ComponentDefinition
Dim oCompOcc As ComponentOccurrence
For Each oCompOcc In oAsmDef.Occurrences
If oCompOcc.Name = "Kollisionsergebnisse" Then
oCompOcc.Delete()
End If
Next
Dim oAllOccurrences As ObjectCollection
oAllOccurrences = oInventorApp.TransientObjects.CreateObjectCollection(oAsmDef.Occurrences)
Dim oResults As InterferenceResults
Try
oResults = oAsmDef.AnalyzeInterference(oAllOccurrences)
Catch ex As Exception
MsgBox("Keine Kollisionen gefunden")
Exit Sub
End Try
Dim oResult As InterferenceResult
Dim totalBody As SurfaceBody
For Each oResult In oResults
If totalBody Is Nothing Then
totalBody = oResult.InterferenceBody
Else
Call oInventorApp.TransientBRep.DoBoolean(totalBody, oResult.InterferenceBody, BooleanTypeEnum.kBooleanTypeUnion)
End If
Next
Dim resultPart As PartDocument
resultPart = oInventorApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, oInventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), False)
Try
Call resultPart.ComponentDefinition.Features.NonParametricBaseFeatures.Add(totalBody)
Catch ex As Exception
MsgBox("Keine Kollisionen gefunden")
Exit Sub
End Try
Dim trans As Matrix
trans = oInventorApp.TransientGeometry.CreateMatrix
Dim oOcc As ComponentOccurrence
oOcc = oAsmDef.Occurrences.AddByComponentDefinition(resultPart.ComponentDefinition, trans)
Call oOcc.SetRenderStyle(StyleSourceTypeEnum.kOverrideRenderStyle, oAsmDoc.RenderStyles.Item("Hellrot"))
oOcc.Name = "Kollisionsergebnisse"
For Each oCompOcc In oAsmDef.Occurrences
oCompOcc.Visible = False
If oCompOcc.Name = "Kollisionsergebnisse" Then
oCompOcc.Visible = True
End If
Next
End Sub