Hi @BeKirra. Sure, that detail can be changed. Below is another example iLogic rule, similar to my first example above, but instead of writing the chosen SketchBlock name to the Description property, it attempts to write it to a custom iProperty. We can not 'add' any new items to the 'standard' iProperties, but can add new properties to the custom ones. iProperties are stored within PropertySets. There are always at least 4 of these PropertySet objects within the PropertySets of every document. The first 3 sets are all standard, so we can not add or remove any properties from those sets, and can only change the values of some of them. The fourth set is always the custom one, but it usually is empty (does not contain any custom properties), until we either create some on purpose, or set some of our parameters to export, which automatically creates a custom iProperty for those parameters, with same name and value as the parameter. So, in order to write something to a custom iProperty, we must make sure the property object we want to write it to exists first. Sometimes that requires creating a new custom iProperty, if the one we want to write to does not already exist.
One of the most popular ways to handle that situation is to use a Try...Catch...End Try statement, which allows us to 'try' some code that we believe may sometimes cause an error (such as trying to access a named property that does not exist), while avoiding that error, and allows us to do something different when it does block the expected error (such as creating the custom property). That process could also be done differently (without using a Try...Catch statement), by iterating through all existing custom properties, and checking their names, to find the one we want first, if it exists. If found, set its value, but if not found, create it.
Sub Main
Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, Inventor.PartDocument)
If oPDoc Is Nothing Then Return
Dim oSBDNames As New List(Of String)
For Each oSBD As SketchBlockDefinition In oPDoc.ComponentDefinition.SketchBlockDefinitions
oSBDNames.Add(oSBD.Name)
Next oSBD
Dim sChosenSBDName As String = InputListBox("Choose SketchBlockDefinition Name To Put In Description.", _
oSBDNames, oSBDNames(0), "SketchBlockDefinition Names", "List of SketchBlockDefinition Names")
If sChosenSBDName <> "" Then
'write the chosen name to a 'custom' iProperty
'to do that, we first need to make sure the custom iProperty exists, or create it
Dim oCProps As Inventor.PropertySet = oPDoc.PropertySets.Item(4) 'always the Custom one
Dim oCProp As Inventor.Property = Nothing
Dim sPropName As String = "SketchBlock Name"
Try 'try to find existing custom iProperty
oCProp = oCProps.Item(sPropName)
'if it was found, then set its value
oCProp.Value = sChosenSBDName
Catch 'getting the custom property failed, so create it, and set its value at same time
oCProp = oCProps.Add(sChosenSBDName, sPropName)
End Try
End If
oPDoc.Update2(True) 'update part, ignoring any errors
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)