Also, in an attempt to fix the odd situation where it is creating a new parameter each time, I decided to replace the whole block of code that deals with the parameter, from using one big Try...Catch block, to using a normal loop of the parameters, to see if the named parameter exists first. Then if it does exist, use a Try...Catch block specifically for setting its Expression, so we can isolate the action, to see if it is having a problem there for some reason. Then if the parameter was not found, use a Try...Catch block specifically for creating the named parameter, to isolate that possible action, and handle any potential error there.
To use this, replace this block of code:
Try 'try to find the specifically named parameter, and set its Expression
oAreaParam = oParams.Item(oParamName)
oAreaParam.Expression = AreaFeet.ToString
Catch 'that parameter was not found, so try to create it
oAreaParam = oParams.UserParameters.AddByExpression(oParamName, AreaFeet.ToString, UnitsTypeEnum.kFootLengthUnits)
Catch
Logger.Error("Unable to find or create parameter named: " & oParamName)
End Try
...with this block of code:
For Each oParam As Inventor.Parameter In oParams
If oParam.Name = oParamName Then
oAreaParam = oParam
Exit For
End If
Next
If oAreaParam IsNot Nothing Then
'it was found, so try to set its Expession
Try
oAreaParam.Expression = AreaFeet.ToString
Catch
Logger.Error("Error while trying to set new value to existing parameter.")
End Try
Else 'named parameter was Nothing (not found), so create it
Try
oAreaParam = oParams.UserParameters.AddByExpression(oParamName, AreaFeet.ToString, UnitsTypeEnum.kFootLengthUnits)
Catch
Logger.Error("Error while trying to create new user parameter.")
End Try
End If
Wesley Crihfield

(Not an Autodesk Employee)