How to obtain Variable table values of a Sheet Metal?

PLM World Member Pioneer PLM World Member Pioneer
PLM World Member Pioneer

Hello All,

 

How to obtain the Variable table values of a Sheet Metal?

 

I tried with the below code:

"Dim objDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing

Dim objVariables As SolidEdgeFramework.Variables = Nothing
Dim objVariable As SolidEdgeFramework.variable = Nothing

 

'Get a reference to the active document

objApp.DisplayAlerts = False
objDoc = objApp.ActiveDocument

objDoc.ReadOnly = False
objApp.DisplayAlerts = False
objApp.Visible = True

'Get a reference to the variables collection
objVariables = objDoc.Variables

For Each objVariable In objDoc.Variables
Debug.Print(objVariable.Name)
Next"

 

But it shows objVariables as Nothing.

 

If i declare objVariables as Object and objDoc as SolidEdgePart.SheetMetalDocument it gives "server threw an exception" or "The parameter is incorrect" exception.

 

Please provide me the sample code.

 

Thank you

1 REPLY

First, you should have posted this in the Developer Forum...

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

First, you should have posted this in the Developer Forum to have more views by the developers.

The following code dumps all variables of the active SE 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