Hi @Ivil. I think I may have something for you to try out. I haven't tested this yet, because I don't have the proper set of files with iProperties set-up to test it on right now, but it seems to me like this might work for you. It is a fairly long code, but I tried to include a lot of comments to tell you what's going on.
Here is the iLogic code:
Sub Main
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "iLogic")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
oADef = oADoc.ComponentDefinition
oOccs = oADef.Occurrences
oMStates = oADef.ModelStates
'make sure main assembly's 'Master' ModelState is 'active'
If oMStates.ActiveModelState.Name <> "Master" Then
oMStates.Item("Master").Activate
End If
'create a dictionary variable to hold the one returned by our Function below
Dim oDictionary As Dictionary(Of String, List(Of ComponentOccurrence))
'run our custom Function, and get the dictionary back from it
oDictionary = CheckComponents(oOccs, "O_Save")
'check to make sure the dictionary contains some items before trying to loop throuh them
If oDictionary.Count = 0 Then
MsgBox("No Components found with matching property or values.", vbInformation, "iLogic")
Exit Sub
End If
For Each oPair In oDictionary
'if no components in its list, then skip to next pair
If oPair.Value.Count = 0 Then Continue For
'get or create the assosiated ModelState, and activate it
'runs our custom Sub routine below
PrepModelState(oMStates, oPair.Key)
For Each oOcc As ComponentOccurrence In oOccs
'if this oOcc is not in the list, then suppress it in this ModelState
If Not oPair.Value.Contains(oOcc) Then
If Not oOcc.Suppressed Then oOcc.Suppress
End If
Next
Next
MsgBox("Process finished.", vbInformation, "iLogic")
End Sub
Sub PrepModelState(oModelStates As ModelStates, oModelStateName As String)
Dim oMState As ModelState
Try
'attempt to find the existing ModelState
oMState = oModelStates.Item(oModelStateName)
Catch
'it was not found, so create it
oMState = oModelStates.Add(oModelStateName)
End Try
oMState.Activate
oModelStates.MemberEditScope = MemberEditScopeEnum.kEditActiveMember
End Sub
Function CheckComponents(oComps As ComponentOccurrences, oPropName As String) As Dictionary(Of String, List(Of ComponentOccurrence))
'create the dictionary variable that this Function is supposed to return
Dim oDict As New Dictionary(Of String, List(Of ComponentOccurrence))
'create the 4 List objects that will be contained within the dictionary
Dim oBeamList As New List(Of ComponentOccurrence)
Dim oPlateList As New List(Of ComponentOccurrence)
Dim oFastenerList As New List(Of ComponentOccurrence)
Dim oOtherList As New List(Of ComponentOccurrence)
'now start looping through the components, and checking them
For Each oComp As ComponentOccurrence In oComps
'get the document that this component represents
Dim oOccDoc As Document = oComp.ReferencedDocumentDescriptor.ReferencedDocument
'get the 'custom' property set
oCProps = oOccDoc.PropertySets.Item(4)
Dim oCProp As Inventor.Property
Try
'tries to find the specified iProperty
oCProp = oCProps.Item(oPropName)
Catch
'the property was not found, so skip to next component
Continue For
End Try
Dim oVal As String = oCProp.Value
'if Value is empty, then skip to next component
If String.IsNullOrEmpty(oVal) Then Continue For
'check value, then add component to related List
If oVal = "Beam" Then
oBeamList.Add(oComp)
ElseIf oVal = "Plate" Then
oPlateList.Add(oComp)
ElseIf oVal = "Fastener" Then
oFastenerList.Add(oComp)
ElseIf oVal = "Other" Then
oOtherList.Add(oComp)
End If
Next
'check lists & add them to the Dictionary with associated Key
If oBeamList.Count > 0 Then
If oDict.ContainsKey("Beam") Then
oDict.Item("Beam") = oBeamList
Else
oDict.Add("Beam", oBeamList)
End If
End If
If oPlateList.Count > 0 Then
If oDict.ContainsKey("Plate") Then
oDict.Item("Plate") = oPlateList
Else
oDict.Add("Plate", oPlateList)
End If
End If
If oFastenerList.Count > 0 Then
If oDict.ContainsKey("Fastener") Then
oDict.Item("Fastener") = oFastenerList
Else
oDict.Add("Fastener", oFastenerList)
End If
End If
If oOtherList.Count > 0 Then
If oDict.ContainsKey("Other") Then
oDict.Item("Other") = oOtherList
Else
oDict.Add("Other", oOtherList)
End If
End If
Return oDict
End Function
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)