Programmer's Guide > Solid Edge > Environments > Part and Sheet Metal > Working with the Variable Table |
The variable system allows you to define relationships between variables and dimensions using equations, external functions, and spreadsheets. For example, you can construct a rectangular profile using four lines, and place two dimensions to control the height and width. The following illustration shows the Variable Table with these two dimensions displayed. (Every dimension is automatically available as a variable.)
Using these variables, you can make the height a function of the width by entering a formula. For example, you could specify that the height is always one-half of the width. Once you have defined this formula, the height is automatically updated when the width changes.
All variables have names; it is through these names that you can reference them. In the preceding illustration, the names automatically assigned by the system are V108 and V109. You can rename these dimensions; in the following illustration, V322 has been renamed to "height," and V323 has been renamed to "width."
Every variable has a value. This can be a static value or the result of a formula. Along with the value, a unit type is also stored for each variable. The unit type specifies what type of measurement unit the value represents. In this example, both of the variables use distance units. You can create Variables for other unit types such as area and angle. Values are displayed using this unit type and the unit readout settings.
All variable automation is accessed through the Variables collection and Variable objects. The Variables collection serves two purposes: it allows you to create and access variable objects, and it allows you to work with dimensions as variables.
The Variables collection supports an Add method to create new Variable objects. It also supports the standard methods for iterating through the members of the collection. The following program connects to the Variables collection, creates three new variables, and lists them.
Units with variables work the same as units in the system. Units are stored using internal values and then are appropriately converted for display. For example, all length units are stored internally as meters. When these units are displayed in the Variable Table, they are converted to the units specified in the Properties dialog box.
In addition to the properties and methods on the Variables collection, properties and methods are also available on the Variable objects. These properties and methods read and set variable names, define formulas, set values, and specify units of measure.
See Handling 'Application is Busy' and 'Call was Rejected By Callee' errors for information regarding the use of OleMessageFilter. |
Variable Table in Visual Basic .NET |
Copy Code
|
---|---|
Imports System.Runtime.InteropServices Module Program <STAThread()> _ Sub Main() Dim objApplication As SolidEdgeFramework.Application = Nothing Dim objPart As SolidEdgePart.PartDocument = Nothing Dim objVariables As SolidEdgeFramework.Variables = Nothing Dim objVariable As SolidEdgeFramework.variable = Nothing Try OleMessageFilter.Register() ' Connect to a running instance of Solid Edge objApplication = Marshal.GetActiveObject("SolidEdge.Application") ' Get a reference to the active document objPart = objApplication.ActiveDocument ' Get a reference to the variables collection objVariables = objPart.Variables 'Add a variable objVariable = objVariables.Add("NewVar", "1.5") 'Change the formula of the variable to a function objVariable.Formula = Math.Sin(0.1).ToString() 'Change the name of the variable objVariable.Name = "NewName" 'Change the value of the variable. This will not change 'the value of the variable objVariable.Value = 123 'Change the formula of the variable to a static value 'This causes the formula to be removed and sets the value objVariable.Formula = "456" 'Change the value of the variable. It works now objVariable.Value = 789 'Delete the variable objVariable.Delete() Catch ex As Exception Console.WriteLine(ex.Message) Finally OleMessageFilter.Revoke() End Try End Sub End Module |
Variable Table in C# |
Copy Code
|
---|---|
using Examples; using SolidEdgeFramework; using System; using System.Runtime.InteropServices; namespace SolidEdge.SDK { class Program { [STAThread] static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgePart.PartDocument part = null; SolidEdgeFramework.Variables variables = null; SolidEdgeFramework.variable variable = null; try { OleMessageFilter.Register(); // Connect to a running instance of Solid Edge application = (SolidEdgeFramework.Application) Marshal.GetActiveObject("SolidEdge.Application"); // Get a reference to the active document part = (SolidEdgePart.PartDocument) application.ActiveDocument; // Get a reference to the variables collection variables = (SolidEdgeFramework.Variables)part.Variables; // Add a variable variable = (SolidEdgeFramework.variable) variables.Add("NewVar", "1.5", UnitTypeConstants.igUnitDistance); // Change the formula of the variable to a function variable.Formula = Math.Sin(0.1).ToString(); // Change the name of the variable variable.Name = "NewName"; // Change the value of the variable. This will not change // the value of the variable variable.Value = 123; // Change the formula of the variable to a static value // This causes the formula to be removed and sets the value variable.Formula = "456"; // Change the value of the variable. It works now variable.Value = 789; //Delete the variable variable.Delete(); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { OleMessageFilter.Revoke(); } } } } |