Update custom iproperty with VBA and iLogic |
Top Previous Next |
This function will do that, but note how it must be called (with a Variant, not with a string or integer):
' Note that the third parameter must be a Variant, not an integer or string Public Sub UpdateCustomiProperty(ByRef Doc As Document, ByRef PropertyName As String, ByRef PropertyValue As Variant) ' Get the custom property set. Dim customPropSet As PropertySet Set customPropSet = Doc.PropertySets.Item("Inventor User Defined Properties")
' Get the existing property, if it exists. Dim prop As Property On Error Resume Next ' How we know if the iProperty already exists Set prop = customPropSet.Item(PropertyName)
' Check to see if the above call failed. If it failed ' then the property doesn't exist. If Err.Number <> 0 Then ' Failed to get the existing property so create a new one. Call customPropSet.Add(PropertyValue, PropertyName) Debug.Print ("Property does not exist so adding it")
Else ' Change the value of the existing property. prop.Value = PropertyValue Debug.Print ("Property exists,just changing it to " & prop.Value) End If
End Sub
|
Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)