It's all in how you set it up.
Here's an example iLogic rule you can test with.
Sub Main
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisAssembly.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oCM As CommandManager = ThisApplication.CommandManager
'get two components to test on
Dim oComp1 As ComponentOccurrence = oCM.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a 'top level' component.")
Dim oComp2 As ComponentOccurrence = oCM.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a 'top level' component.")
'attempt to create the attribute on each one (Value should be different for each one, in order to tell them apart later)
TryAddAttribute(oComp1, "MySet", "ID", ValueTypeEnum.kStringType, "Comp One")
TryAddAttribute(oComp2, "MySet", "ID", ValueTypeEnum.kStringType, "Comp Two")
'now retrieve the components, based only on the different attribute values
Dim oCol1 As ObjectCollection = oADoc.AttributeManager.FindObjects("MySet", "ID", "Comp One")
Dim oComp1Returned As ComponentOccurrence = oCol1.Item(1)
Dim oCol2 As ObjectCollection = oADoc.AttributeManager.FindObjects("MySet", "ID", "Comp Two")
Dim oComp2Returned As ComponentOccurrence = oCol2.Item(1)
MsgBox("oCol1.Count = " & oCol1.Count & " and oComp1Returned.Name = " & oComp1Returned.Name, , "")
MsgBox("oCol2.Count = " & oCol2.Count & " and oComp2Returned.Name = " & oComp2Returned.Name, , "")
End Sub
Sub TryAddAttribute(oOcc As ComponentOccurrence, oSetName As String, oName As String, oValueType As ValueTypeEnum, oValue As Object)
Dim oComp As ComponentOccurrence = oOcc
Dim oSet As AttributeSet
Dim oAtt As Attribute
If oComp.AttributeSets.Count = 0 Then
'there are no sets, so create the set, and the attribute
oSet = oComp.AttributeSets.Add(oSetName, False)
oAtt = oSet.Add(oName, oValueType, oValue)
Exit Sub
End If
'There is more than one AttributeSet attached to it so check for 'this' set
If oComp.AttributeSets.NameIsUsed(oSetName) Then
'the set already exists so get it
oSet = oComp.AttributeSets.Item(oSetName)
Else
'that set wasn't found, so create it, then create the attribute
oSet = oComp.AttributeSets.Add(oSetName, False)
oAtt = oSet.Add(oName, oValueType, oValue)
Exit Sub
End If
'set was found, so check for the attribute
If oSet.NameIsUsed(oName) Then
'an attribute with that name was found so get it
oAtt = oSet.Item(oName)
Else
'that attribute wasn't found, so create it
oAtt = oSet.Add(oName, oValueType, oValue)
Exit Sub
End If
'check the 'ValueType' of the existing attribute
If oAtt.ValueType = oValueType Then
If oAtt.Value = oValue Then
MsgBox("That exact attribute already exists. Exiting.", , "")
Exit Sub
Else
'An attribute by that name and type already exist, but it has a different value
MsgBox("An Attribute with that 'Name' and 'ValueType' already exists, but it has a different 'value'.", , "")
Exit Sub
End If
Else
'an attribute by that name was found, but it has a different ValueType, so let user know
MsgBox("There is an existing Attribute by that name, but it has a different 'ValueType'." & vbCrLf & _
"Moving on, without changing it and without creating a new one.", , "")
Exit Sub
End If
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)