Moved:

How to obtain Variable table values of a Sheet Metal?

Siemens Legend Siemens Legend
Siemens Legend
1 REPLY

Jerry, the following code dumps all variables of any acti...

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Jerry,

the following code dumps all variables of any active document into a file:

Imports SolidEdgeFrameworkSuppport
Imports SolidEdgeFramework

Module Module1

  Sub Main()
    Dim objApp As SolidEdgeFramework.Application = Nothing
    Try
      ' Connect to an existing instance of Solid Edge
      objApp = Marshal.GetActiveObject("SolidEdge.Application")
      Try
        FileOpen(1, "C:\TEMP\Variables.txt", OpenMode.Output)
        DumpVars(objApp.ActiveDocument)
        FileClose(1)
      Catch ex As Exception
        MessageBox.Show("Exception caught during macro:" & vbCrLf & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
      End Try
    Catch
      MessageBox.Show("Solid Edge is not running", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Finally
      If Not (objApp Is Nothing) Then
        Marshal.ReleaseComObject(objApp)
      End If
    End Try
  End Sub
  
  Sub DumpVariable(ByVal objVar As variable)
    Dim factor As Double = 1.0
    Select Case objVar.UnitsType
      Case UnitTypeConstants.igUnitAngle
        factor = 180.0 / Math.PI
        Print(1, String.Format("  Var: {0,-20} = {1,5:0.0} deg", objVar.Name, objVar.Value * factor))
      Case UnitTypeConstants.igUnitDistance
        factor = 1000.0
        Print(1, String.Format("  Var: {0,-20} = {1,5:0.0} mm", objVar.Name, objVar.Value * factor))
      Case UnitTypeConstants.igUnitScalar
        Print(1, String.Format("  Var: {0,-20} = {1,5} ", objVar.Name, objVar.Value))
    End Select
    Dim strFormula As String = objVar.Formula
    If Not String.IsNullOrEmpty(strFormula) Then
      Print(1, " | " & strFormula)
    End If
    Dim values(0) As Double
    objVar.GetDiscreteValues(values)
    If values.GetLength(0) > 0 Then
      Print(1, " {")
      For i = values.GetLowerBound(0) To values.GetUpperBound(0)
        If i < values.GetUpperBound(0) Then
          Print(1, (values.GetValue(i) * factor).ToString() + ";")
        Else
          Print(1, (values.GetValue(i) * factor).ToString() + "}")
        End If
      Next
    End If
    PrintLine(1, "")
  End Sub

  Sub DumpDimension(ByVal objVars As Variables, ByVal objDim As Dimension)
    Dim strName As String = objVars.GetDisplayName(objDim)
    Select Case objDim.DimensionType
      Case DimTypeConstants.igDimTypeAngular
      Case DimTypeConstants.igDimTypeArcAngle
      Case DimTypeConstants.igDimTypeAngularCoordinate
        Print(1, String.Format("  Dim: {0,-20} = {1,5:0.0} deg", strName, objDim.Value * 180.0 / Math.PI))
      Case Else
        Print(1, String.Format("  Dim: {0,-20} = {1,5:0.0} mm", strName, objDim.Value * 1000.0))
    End Select
    Dim strFormula As String = objVars.GetFormula(strName)
    If Not String.IsNullOrEmpty(strFormula) Then
      Print(1, " | " & strFormula)
    End If
    PrintLine(1, "")
  End Sub

  Sub DumpVars(ByVal objDoc As SolidEdgeDocument)
    PrintLine(1, vbCrLf & objDoc.Name)
    PrintLine(1, "---------------------------------------")
    Dim objVars As Variables = objDoc.Variables
    Dim objVarList As VariableList = objVars.Query("*", _
                    SolidEdgeConstants.VariableNameBy.seVariableNameByBoth, _
                    SolidEdgeConstants.VariableVarType.SeVariableVarTypeBoth)
    For Each objVar In objVarList
      Select Case objVar.Type
        Case SolidEdgeConstants.ObjectType.igDimension
          DumpDimension(objVars, objVar)
        Case SolidEdgeConstants.ObjectType.igVariable
          DumpVariable(objVar)
        Case SolidEdgeConstants.ObjectType.igAsmRefPlane ' Only exists in assemblies
          PrintLine(1, "  Pln: " & objVars.GetName(objVar) & " = ?? | " & objVars.GetFormula(objVars.GetName(objVar)))
      End Select
    Next
  End Sub

End Module