- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.RangeBoxChanged to
Set CutBox = AssDoc.ComponentDefinition.Occurrences.ItemByName("Cube:1").RangeBoxAnd it worked