Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Updating User Text Type Parameter crashes Inventor

2 REPLIES 2
Reply
Message 1 of 3
andrewwhiteinc
333 Views, 2 Replies

Updating User Text Type Parameter crashes Inventor

Hey Ladies and Gents, just wondering is anyone else had this issue and how they might have resolved it:

 

This crashes Inventor at this line: oParams(i).Expression = ... only when oParams(i) is a text type user parameter, works for numeric

 

for example in module:

...

 

UpdateTextParameter("DOC_TYPE", "PIPING_ASSEMBLY", PlumbingAssemblyTemp)

...

 

Function UpdateTextParameter(ByVal ParameterName AsString, ByVal NewExpression AsString, OptionalByVal SpecdDoc As Inventor.Document = Nothing)

If GetINV() = FalseThenReturn 0 'Gets an active Inventor instance

Dim oDoc As Inventor.Document = Nothing

If IsNothing(SpecdDoc) = True Then

oDoc = oINV.ActiveEditDocument

EndIf

If IsNothing(SpecdDoc) = False Then

oDoc = SpecdDoc

EndIf

Dim oParams As Inventor.Parameters = oDoc.ComponentDefinition.Parameters

If IsNothing(NewExpression) = TrueThen

msgbox("The new expression to be entered into the parameter """ & ParameterName & """ is null which would crash Inventor. Skipping operation.") 'I've found this issue out already

Return 0

EndIf

For i = 1 To oParams.Count

If UCase(oParams(i).Name) = UCase(ParameterName) Then

oParams(i).Expression = """" & NewExpression & """" 'crashes here always, I've also tried oParams(i).Expression = NewExpression to the same affect

Return 0

EndIf

If i = oParams.Count Then

 msgbox("A parameter named: " & ParameterName & " was not found in the active document.")

EndIf

Next

Return 0

EndFunction

P. Andrew White, P.Eng
Manufacturing Engineering Manager
Silent-Aire Manufacturing
2 REPLIES 2
Message 2 of 3

I got this figured, oddly enough, if i put

 

oParams(i).Value = NewExpression

instead of

oParams(i).Expression = NewExpression

 

it works and doesn;t crash inventor

P. Andrew White, P.Eng
Manufacturing Engineering Manager
Silent-Aire Manufacturing
Message 3 of 3
rjay75
in reply to: andrewwhiteinc

The reason is the expression of a Parameter with Text units must evaluate to a text expression. For instance:

 

Expression = "2.0 in" <- String value that gets evaluated to a double with the Value = 5.08.

Expression = "\"Some Text \"" <- String value that evaluates to a string with the Value = "Some Text". (Notice the escaped quotes in the expression.)

 

It can be confusing but you have to remember whether you're working with the string value or an expression that evaluates to a string.

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report