I have an iassembly with some lengthy and unique ilogic to control what parts are included / excluded based on user inputs in a form. To begin, the program includes all components, and then excludes the ones that aren't needed. This is basically, briefly what the first part of that looks like:
For Each oCompOcc In oCompDef.Occurrences
i=i+1
'Include all currently excluded components
If oCompOcc.Excluded=True Then
oAssObj=oCompDef.Occurrences.Item(i)
oDoc.SelectSet.Select(oAssObj)
ThisApplication.CommandManager.ControlDefinitions.Item("ExcludeCtxCmd").Execute()InventorVb.DocumentUpdate()
Else
End If
Next
InventorVb.DocumentUpdate()
So this works just fine, mostly. I run into an issue with the component occurrences that are within patterns (I have 2 patterns - 1 circular and 1 rectangular). This code will "Include" all occurrences inside an "Excluded" pattern, but the pattern itself remains "Excluded". In other words, in the browser, the pattern name appears greyed out and crossed out, but all the elements and the components within them appear "alive", so to speak. But the BOM indicates a Qty. of ZERO for these components since the pattern that.
I can toggle include / exclude of patterns using the same method:
oDoc.SelectSet.Select(oPattern)
ThisApplication.CommandManager.ControlDefinitions.Item("ExcludeCtxCmd").Execute()
But it seems I can't identify which patterns are excluded to start with, like:
If oPattern.Excluded=True Then...
I get an error when I try this. Is there a way around it? Am I missing something? How can I find and select excluded component patterns in order to toggle them to "Include"?
Ideas?
Thanks.
Hi,
I do not either find Exclude property for pattern. But I did not make a similar test file as yours. Could you share a copy? Thanks.
Okay, here's what I ended up doing. My coding may not be the best but it is working. The goal is to get all the components to an Included state in order to selectively exclude them. It is specific to my situation and works only because I know what components are patterned and I can find them by name. These components only exist in patterns in my assembly; not stand-alone.
I iterated through all the occurrences (which includes those consumed by patterns, but not the patterns themselves) and if any one is excluded, I include it. I have an "if...then..." statement that follows which sets variables if the occurrence is of a certain name, meaning if it is one of those in a pattern. Then I toggle Include/Exclude twice for the patterns, so that if they were included to begin with, they still are, and if they were excluded, they still are. What this does, though, is make sure that if any of the individuals in the pattern is excluded but the pattern itself is included, the pattern and its components are made to be in the same excluded state. Further down, I look to those variable names I mentioned and if they are a certain value (meaning that a pattern has excluded components inside it), I toggle them to "Include". End result: all components and patterns are included.
Dim app As Inventor.Application = ThisApplication
Dim oDoc As Inventor.AssemblyDocument = app.ActiveDocument
Dim oCompDef As Inventor.ComponentDefinition = oDoc.ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
Dim oAssObj As ComponentOccurrence
Dim oPattern As OccurrencePattern
Dim oPatterns As OccurrencePatterns = oCompDef.OccurrencePatterns
Dim oElement As OccurrencePatternElement
Dim oElements As OccurrencePatternElements
Dim pattexc1 as Double = 0
Dim pattexc2 as Double = 0
oDoc.SelectSet.Clear
Dim i As Integer = 0
For Each oCompOcc In oCompDef.Occurrences
i=i+1
'Include all currently excluded components
If oCompOcc.Excluded = True Then
If oCompOcc.Name Like "CAPSCREW HH 3/8*" Or oCompOcc.Name Like "WASHER LOCK 3/8*" Then
pattexc1 = 38
ElseIf oCompOcc.Name Like "CAPSCREW HH 1/2*" Or oCompOcc.Name Like "WASHER LOCK 1/2*" Then
pattexc2 = 12
Else
oAssObj = oCompDef.Occurrences.Item(i)
oDoc.SelectSet.Select(oAssObj)
ThisApplication.CommandManager.ControlDefinitions.?Item("ExcludeCtxCmd").Execute()
InventorVb.DocumentUpdate()
End If
End If
Next
oDoc.SelectSet.Clear
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("3/8 bolts & locks")
oDoc.SelectSet.Select(oPattern)
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("1/2 bolts & locks")
oDoc.SelectSet.Select(oPattern)
ThisApplication.CommandManager.ControlDefinitions.?Item("ExcludeCtxCmd").Execute()
ThisApplication.CommandManager.ControlDefinitions.?Item("ExcludeCtxCmd").Execute()
If pattexc1 = 38 Then
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("3/8 bolts & locks")
oDoc.SelectSet.Select(oPattern)
ThisApplication.CommandManager.ControlDefinitions.?Item("ExcludeCtxCmd").Execute()
ElseIf pattexc2 = 12 Then
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("1/2 bolts & locks")
oDoc.SelectSet.Select(oPattern)
ThisApplication.CommandManager.ControlDefinitions.?Item("ExcludeCtxCmd").Execute()
End If
oDoc.SelectSet.Clear
InventorVb.DocumentUpdate()
'Now all are included