Get Expression Type

Hi

I am making a journal, where I am extracting certain expressions to a txt file, Name and Value, but found that the Expressions which are specified as a String does not have the "Value" property. Therefore I want to get the Expression type (Number, String, Vector etc.) for each expression, in order to de differentiate the extration of values in the code. Is it possible to get the type?

I cannot use the built in Expression Export function, since this will export the formular if a formular is given, and not the value of the formular.

Thanks!

Best regards,
Morten T Nielsen

Unfortunately, each expression type has its own "get value" method. Fortunately, you can use the expression's .Type property to determine which method to use.


Option Strict Off
Imports System
Imports NXOpen

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

For Each myExp As Expression In workPart.Expressions
lw.WriteLine(myExp.Name & " type: " & myExp.Type)
Try
Select Case myExp.Type.ToLower
Case Is = "string"
lw.WriteLine(myExp.StringValue)
Case Is = "number"
lw.WriteLine(myExp.Value)
Case Is = "integer"
lw.WriteLine(myExp.IntegerValue)
Case Is = "boolean"
lw.WriteLine(myExp.BooleanValue)
Case Else
lw.WriteLine("expression is of type: " & myExp.Type)
lw.WriteLine("add this type into the select case block")
End Select

Catch ex As NXException
lw.WriteLine(ex.ErrorCode & ": " & ex.Message)
End Try
lw.WriteLine("")
Next

End Sub

End Module