Do all custom iProperties require a string output?

Do all custom iProperties require a string output?

JBEDsol
Collaborator Collaborator
321 Views
2 Replies
Message 1 of 3

Do all custom iProperties require a string output?

JBEDsol
Collaborator
Collaborator

I'm trying to set up a code where I can update an iProperty based on inputs.  I modified the example code to update iProperties.  The sub would be used with texts, bools, and numbers.  I set the input as a variant but get errors if I pass anything other than a variant or string.  What's the rules on iProps?

Public Sub CalliProp()

Dim docCurr As Document
Set docCurr = ThisApplication.ActiveDocument

Dim dblTest As Double
dblTest = 3.22222

Call UpdateCustomiProp(docCurr, "Woohah", dblTest)

End Sub
Public Sub UpdateCustomiProp(docDoc As Document, strPropTitle As String, varValue As Variant)
       
    ' Get the custom property set.
    Dim psCustom As PropertySet
    Set psCustom = docDoc.PropertySets.Item("Inventor User Defined Properties")
        
    Dim propCurrent As Property
    Set propCurrent = psCustom.Item(strPropTitle)
    
    If Err.Number <> 0 Then
        ' Failed to get the property, which means it doesn't exist
        ' so we'll create it.
        Call psCustom.Add(varValue, strPropTitle)
    Else
        ' Got the property so update the value.
        propCurrent.Value = varValue
    End If

End Sub
0 Likes
322 Views
2 Replies
Replies (2)
Message 2 of 3

omartin
Advocate
Advocate

Custom iProps can be what ever type that is available when you go and add one manually.

You can use the object type instead of variant to make it generic.

Keep in mind the iproperty type will change depending on what type of value you assign ex: assigning "123" and 123 will change the iproperty type automatically between string and number.

Was my reply Helpful ? send a Kudos or accept as solution
0 Likes
Message 3 of 3

JBEDsol
Collaborator
Collaborator

I found out if I use byval in front of the variant designation for my sub it works

0 Likes