Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
fakeru
354 Views, 2 Replies

Box.IsDisjoint Method

I'm trying to suppress with VBA all occurrences in assembly based on the condition if they intersect a part(cube:1).

I'm using rangeboxes for that and IsDisjoint methond. However nothing works as I expect.

Public Sub CutBox()
Dim AssDoc As AssemblyDocument
 Set AssDoc = ThisApplication.ActiveDocument
        Dim oAsmCompDef As Inventor.AssemblyComponentDefinition
        Set oAsmCompDef = AssDoc.ComponentDefinition
        Dim oOcc As ComponentOccurrence
        
        Dim CutBox As Box
       Set CutBox = AssDoc.ComponentDefinition.Occurrences.ItemByName("Cube:1").Definition.RangeBox
        For Each oOcc In oAsmCompDef.Occurrences
            If oOcc.Definition.RangeBox.IsDisjoint(CutBox) = True Then
                oOcc.Suppress
            End If
        Next

End Sub

 

Any idea what's wrong? I'm sure that some occurrences' rangebox do not intersect the cube's part range box, but Inventor doesn't suppress those occurrences.

 

Regards

Alexandru

Autodesk Inventor 2015 Certified Professional
fakeru
in reply to: fakeru

I found the solution myself. I had to delcare and set the rangebox of each occurrence:

Dim oRB As Box
Set oRB = oOcc.RangeBox

 

So the entire code looks like this:

Public Sub CopySketch()

 Dim AssDoc As Inventor.AssemblyDocument
 Set AssDoc = ThisApplication.ActiveDocument
        Dim oAsmCompDef As Inventor.AssemblyComponentDefinition
        Set oAsmCompDef = AssDoc.ComponentDefinition
        Dim oOcc As ComponentOccurrence
        
        Dim CutBox As Box
       Set CutBox = AssDoc.ComponentDefinition.Occurrences.ItemByName("Cube:1").Definition.RangeBox
        For Each oOcc In oAsmCompDef.Occurrences
        
         Dim oRB As Box
        Set oRB = oOcc.RangeBox
            If oRB.IsDisjoint(CutBox) = True Then

                oOcc.Suppress
            End If
        Next

End Sub

 

Autodesk Inventor 2015 Certified Professional
fakeru
in reply to: fakeru

Actually that didn't fix the problem.

The code doesn't work in a consisten manner. Occurrences are being suppressed not based on the rangeboxes interference. 

 

Later edit:

Now it seems like I found the problem. It was in this line: 

Set CutBox = AssDoc.ComponentDefinition.Occurrences.ItemByName("Cube:1").Definition.RangeBox

 Changed to

Set CutBox = AssDoc.ComponentDefinition.Occurrences.ItemByName("Cube:1").RangeBox

And it worked 

Autodesk Inventor 2015 Certified Professional