Hi @Guthery1. I did not know if you intended to pre-select the components, or select them after you run the rule, so I designed this rule with pre-selection in mind. If you run the rule with nothing pre-selected, it will let you know, then exit the rule. If there is something pre-selected, it will then prompt you to enter the name of the property, then the value for it. Then it will iterate through the selected items, making sure they are assembly components, then either creating new, or updating existing instance properties in them.
Dim oSS As SelectSet = ThisDoc.Document.SelectSet
If oSS.Count = 0 Then
MsgBox("Nothing Pre-Selected - exiting rule", vbCritical, "iLogic")
Return
End If
Dim sPropertyName As String = InputBox("Enter Property Name", "Property Name", "")
If sPropertyName = "" Then Return
Dim oPropertyValue As Object = InputBox("Enter Property Value", "Property Value")
If oPropertyValue Is Nothing Then Return
For Each oObj In oSS
If TypeOf oObj Is ComponentOccurrence Then
Dim oOcc As ComponentOccurrence = oObj
oOcc.OccurrencePropertySetsEnabled = True
Dim oPropSet As PropertySet = oOcc.OccurrencePropertySets.Item(1)
Dim oProp As Inventor.Property = Nothing
Try
oProp = oPropSet.Item(sPropertyName)
Catch
oProp = oPropSet.Add(oPropertyValue, sPropertyName)
End Try
If oProp IsNot Nothing AndAlso oProp.Value <> oPropertyValue Then
Try : oProp.Value = oPropertyValue : Catch : End Try
End If
End If
Next 'oObj
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)