Showing results for 
Search instead for 
Did you mean: 

Export customized Expression List with vb



I am trying to export my expression list in an exp file where I need to get all Names, Values (not formular!) and units

I have the following code:


For Each nx_expr As Expression In exprs
 FirstTwoDigits = Left(nx_expr.Name, 2)
  If FirstTwoDigits = "AA" Then
        If nx_expr.Type = "Number" Then
           file.WriteLine("[" & nx_expr.Units.Abbreviation & "]" & nx_expr.Name & "=" & Replace(nx_expr.Value,",","."))
          If nx_expr.Type = "String" Then
              file.WriteLine("(String) " & nx_expr.Name & "=""" & nx_expr.StringValue & """")

              If nx_expr.Type = "List" Then
              file.WriteLine("(List) " & nx_expr.Name & "=" & nx_expr.GetListValue())

          End If
     End If
  End If
  cnt += 1 
End If
Next nx_expr


With the Number and the String it is working but for the Lists not! How do I have to use the Method GetListValue().

The output should be: (List) pListname=1;2;3;4;5;...


2. One other problem I have is the unitless Parameters. They are from the type "Number" but there will be a error because nx_expr.Units.Abbreviation is not working for unitless. How can I do an differentiation (There is not function for getting the dimensionality)

Thank you very much,



Re: Export customized Expression List with vb

Siemens Legend Siemens Legend
Siemens Legend

The .NET method Expression.GetListValue() returns an array System.Object[] and for constant expressions the unit can be checked against null (C#) / Nothing (VB).


Something like this should work:



Imports System
Imports NXOpen

Module NXJournal

Sub Main
    Dim theSession As Session = Session.GetSession()
    Dim theLW As ListingWindow = theSession.ListingWindow
    Dim sValue, sUnit As String

    For Each expr As Expression In theSession.Parts.Work.Expressions

        If expr.Units Is Nothing Then
            sUnit = "const"
            sUnit = expr.Units.TypeName 'Name deprecated since NX11.0.1
        End If

        If expr.Type.Equals("Number") Then
            sValue = expr.Value
        Else If expr.Type.Equals("List") Then
            sValue = "{"
            Dim objs As Object() = expr.GetListValue()
            For ii As Integer = 0 To objs.Length-1
                sValue = sValue + objs(ii).ToString()
                If ii < objs.Length-1 Then sValue = sValue + ","
            sValue = sValue + "}"
        End If

        theLW.WriteLine(expr.Name & " (" & expr.Type & ")" & " = " & sValue & " (" & sUnit & ")")

End Sub
End Module

Output will be like:


mynumber (Number) = 123,567 (MilliMeter)
mymixedlist (List) = {True,1,2,abc} (const)




Re: Export customized Expression List with vb


perfect! it works - thank you!