Box.IsDisjoint Method

Box.IsDisjoint Method

fakeru
Advocate Advocate
401 Views
2 Replies
Message 1 of 3

Box.IsDisjoint Method

fakeru
Advocate
Advocate

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
0 Likes
402 Views
2 Replies
Replies (2)
Message 2 of 3

fakeru
Advocate
Advocate

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
0 Likes
Message 3 of 3

fakeru
Advocate
Advocate

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
0 Likes