Question: In an Assembly, can API do Boolean on two occurrences? I want to have the intersection of two bodies from InterferenceResult.
Solution: It is possible to create a TransientBRep that is exactly similar to an occurrence using TransientBRep.Copy method and provide the surface body of the occurrence. If in a part with multi-bodies (from Inventor 2010), you could also do Boolean by this way.
- Create Transient1 & Transient2 based on Occ1 & Occ2 (with TransientBRep.Copy)
- Do Boolean between Transient1 & Transient2 using "kBooleanTypeDifference"
- Create NonParametricBaseFeature based on the result.
If in a part with multi-bodies, the NonParametricBaseFeature can be added directly to the part.
If in an assembly, because AssemblyComponentDefinition has no NonParametricBaseFeatures, it requires to create a new part and insert the result body to the part, finally, place the part to the assembly.
Following is a code sample for assembly. It needs an assembly with at least two occurrences and it assumes the first and second occurrence in an assembly intersect each other.
Sub TransientBRep_DoBoolean()
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
Dim oOcc1 As ComponentOccurrence
Set oOcc1 = oAsmDoc.ComponentDefinition.Occurrences(1)
Dim oOcc2 As ComponentOccurrence
Set oOcc2 = oAsmDoc.ComponentDefinition.Occurrences(2)
Dim oTransientBRep As TransientBRep
Set oTransientBRep = ThisApplication.TransientBRep
Dim oBody1 As SurfaceBody
Set oBody1 = oTransientBRep _
.Copy(oOcc1.Definition.SurfaceBodies(1))
Dim oBody2 As SurfaceBody
Set oBody2 = oTransientBRep _
.Copy(oOcc2.Definition.SurfaceBodies(1))
Call oTransientBRep.Transform( _
oBody1, oOcc1.Transformation)
Call oTransientBRep.Transform( _
oBody2, oOcc2.Transformation)
'do DoBoolean on the two bodies
Call oTransientBRep.DoBoolean( _
oBody1, oBody2, kBooleanTypeDifference)
'add the result body to a new part
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents _
.Add(kPartDocumentObject, _
ThisApplication.FileManager _
.GetTemplateFile(kPartDocumentObject), _
False)
Call oPartDoc.ComponentDefinition.Features _
.NonParametricBaseFeatures.Add(oBody1)
'save the new part
Call oPartDoc.SaveAs("c:\temp\DifferencePart.ipt", False)
'add the new part to the assembly
Call oAsmDoc.ComponentDefinition _
.Occurrences.AddByComponentDefinition( _
oPartDoc.ComponentDefinition, _
oOcc1.Transformation)
'hide parent components
oOcc1.Visible = False
oOcc2.Visible = False
End Sub