Sunday 5 October 2014

Making of Purge Variables for Solid Edge - Part 2

...continued from Part 1

The top part of the code has the Imports statements:

Imports System.Runtime.InteropServices
Imports SolidEdgeFrameworkSupport
Imports SolidEdgeFramework

where as in the Form class the required variables are declared as below:

Public Class Form1
    Dim oApp As SolidEdgeFramework.Application = Nothing
    Dim oDoc As SolidEdgeDocument = Nothing

    Dim lName As List(Of String) = New List(Of String)
    Dim lFormula As List(Of String) = New List(Of String)

    Const sTitle As String = "Purge Variables"

The lName and lFormula are lists of Strings. lName stores the name of variables and the lFormula the formula.

In the Form's Load event, first Solid Edge is checked to be running followed by checking if at least one document is open. If the command is run from a button on the Ribbon, there is no need to include these checks.

On Error Resume Next

oApp = Marshal.GetActiveObject("SolidEdge.Application")

If oApp Is Nothing Then
  MessageBox.Show("Solid Edge should be running.", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

If oApp.Documents.Count < 1 Then
  MessageBox.Show("A document should be open.", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

If there indeed is a document open, it is assigned to oDoc and all variables from its variable table are stored in oVars:

oDoc = oApp.ActiveDocument
Dim oVars As Variables = oDoc.Variables

These variables consists of both user variables and dimension variables.

It We are interested in just the user variables so using a VariableList, the variables in oVars are queried to get just the user variables:

Dim oVarList As VariableList = oVars.Query("*", SolidEdgeConstants.VariableNameBy.seVariableNameByUser, SolidEdgeConstants.VariableVarType.SeVariableVarTypeVariable)

The last argument which is an enum SeVariableVarTypeVariable returns just the user variables. The other value of the enum is SeVariableVarTypeDimension which returns the dimension variables.

The first argument to the Query function is "*" which means all. So using "T*" will return all variables whose first letter is T.

Once we have all the user variables, it is time to separate their names and formulas into two lists as declared earlier.

For this, a For Each loop is used as below and the respective list is flooded:

For Each oVar As variable In oVarList
  If oVar.Type = SolidEdgeConstants.ObjectType.igVariable Then
  End If

Continued to Part 3...

Index of all Solid Edge Tutorials, Tips, Videos...

No comments:

Post a Comment