Solid Edge ST7 SDK
Working with Dimensions

This topic contains these sections:
Working with Dimensions

Solid Edge allows you to place and edit dimensions on elements. In the Profile environment, dimension objects control the size and orientation of geometry.

Dimensions can be linear, radial, or angular. Dimensions supply information about the measurements of elements, such as the angle of a line or the distance between two points. A dimension is related to the element on which it is placed. In the Profile environment, the dimensions control the geometry; if the dimension changes, the geometry updates.

In a Part document, the Dimensions collection is accessed through the Profile object. The Dimensions collection provides the methods for placing dimensions and for iterating through all the dimensions on the entire sheet or profile.

Linear Dimensions
A linear dimension measures the distance between two or more elements, the length of a line, or an arc's length. For a complete description of the properties that define how a linear dimension is placed, see the Programming with Solid Edge on-line Help.

Radial Dimensions
Radial dimensions measure the radius or diameter at a point on the element. These dimensions are similar except that they show the radius or diameter value depending on the type. With the ProjectionArc and TrackAngle properties, you can define the measurement point on the element.

Angular Dimensions
Angular dimensions measure the angle between two lines or three points. An angular dimension defines two intersecting vectors and four minor sectors. These sectors are distinguished according to whether the angle is measured in the sector where the vector direction goes outward from the intersection point or comes inward, and whether the angle is measured in the clockwise or counterclockwise direction.

The angles are always measured in the counterclockwise direction with both vector directions going outward from the intersection point (sector one condition). To measure in any other angle, certain properties are set so that the dimension object modifies the vector direction and computes the angle.

Placing Dimensions

In the Profile environment, driving dimensions control the elements to which they refer. When you edit a driving dimension, the geometry of the element that is related to that dimension is modified.

You can place dimensions only on existing elements. A set of Add methods is provided on the Dimensions collection, one for each type of dimension. The element to which the dimension is attached determines the type of dimension (driving or driven) that will be placed. The Add methods on the Dimensions collection object take minimal input and place the dimensions with specific default values.

When you place dimensions between two elements interactively, the dimensions are measured at a specific location on an element. For example, when you place a dimension between the end points of two lines, you select one end of each line. When you place dimensions through automation, you specify a point on the element and a key point flag to define the dimension.

In the following program, four lines are drawn and connected with key point relationships. The lengths of two of the lines and the distance between two lines are dimensioned. The dimension is set to be a driving dimension so it will control the length and position of the geometry. The sample also shows how to modify a dimension style by changing the units of measurement of one of the dimensions to meters.

See Handling 'Application is Busy' and 'Call was Rejected By Callee' errors for information regarding the use of OleMessageFilter.
Placing Dimensions in Visual Basic .NET
Copy Code
Imports SolidEdgeConstants
Imports System.Runtime.InteropServices

Module Program
    <STAThread()> _
    Sub Main()
        Dim objApplication As SolidEdgeFramework.Application = Nothing
        Dim objDocuments As SolidEdgeFramework.Documents = Nothing
        Dim objPart As SolidEdgePart.PartDocument = Nothing
        Dim objProfileSets As SolidEdgePart.ProfileSets = Nothing
        Dim objProfileSet As SolidEdgePart.ProfileSet = Nothing
        Dim objProfiles As SolidEdgePart.Profiles = Nothing
        Dim objProfile As SolidEdgePart.Profile = Nothing
        Dim objRefPlanes As SolidEdgePart.RefPlanes = Nothing
        Dim objRefPlane As SolidEdgePart.RefPlane = Nothing
        Dim objLines2d As SolidEdgeFrameworkSupport.Lines2d = Nothing
        Dim aLine2d(0 To 3) As SolidEdgeFrameworkSupport.Line2d
        Dim objRelations2d As SolidEdgeFrameworkSupport.Relations2d = Nothing
        Dim objDimensions As SolidEdgeFrameworkSupport.Dimensions = Nothing
        Dim objDimension As SolidEdgeFrameworkSupport.Dimension = Nothing
        Dim objDimStyle As SolidEdgeFrameworkSupport.DimStyle = Nothing
        Dim i As Integer

        Try
            OleMessageFilter.Register()

            ' Connect to a running instance of Solid Edge
            objApplication = Marshal.GetActiveObject("SolidEdge.Application")

            ' Get a reference to the documents collection
            objDocuments = objApplication.Documents

            ' Add a Part document      
            objPart = objDocuments.Add("SolidEdge.PartDocument")

            ' Get a reference to the ref planes collection
            objRefPlanes = objPart.RefPlanes

            ' Get a reference to the first reference plane
            objRefPlane = objRefPlanes.Item(1)

            ' Get a reference to the profile sets collection
            objProfileSets = objPart.ProfileSets

            ' Add a new profile set
            objProfileSet = objProfileSets.Add()

            ' Get a reference to the profiles collection
            objProfiles = objProfileSet.Profiles

            ' Add a new profile on the selected reference plane
            objProfile = objProfiles.Add(objRefPlane)

            ' Get a reference to the lines 2d collection
            objLines2d = objProfile.Lines2d

            ' Get a reference to the relations 2d collection
            objRelations2d = objProfile.Relations2d

            ' Get a reference to the dimensions collection
            objDimensions = objProfile.Dimensions

            ' Draw the geometry.
            aLine2d(0) = objLines2d.AddBy2Points(0, 0, 0.1, 0)
            aLine2d(1) = objLines2d.AddBy2Points(0.1, 0, 0.1, 0.1)
            aLine2d(2) = objLines2d.AddBy2Points(0.1, 0.1, 0, 0.05)
            aLine2d(3) = objLines2d.AddBy2Points(0, 0.05, 0, 0)

            ' Add endpoint relationships between the lines
            objRelations2d.AddKeypoint( _
              aLine2d(0), _
              KeypointIndexConstants.igLineEnd, _
              aLine2d(1), _
              KeypointIndexConstants.igLineStart)

            objRelations2d.AddKeypoint( _
              aLine2d(1), _
              KeypointIndexConstants.igLineEnd, _
              aLine2d(2), _
              KeypointIndexConstants.igLineStart)

            objRelations2d.AddKeypoint( _
              aLine2d(2), _
              KeypointIndexConstants.igLineEnd, _
              aLine2d(3), _
              KeypointIndexConstants.igLineStart)

            objRelations2d.AddKeypoint( _
                          aLine2d(3), _
              KeypointIndexConstants.igLineEnd, _
              aLine2d(0), _
              KeypointIndexConstants.igLineStart)

            ' Add dimensions, and change the dimension units to meters
            objDimension = objDimensions.AddLength(aLine2d(1))

            objDimension.Constraint = True
            objDimStyle = objDimension.Style
            objDimStyle.PrimaryUnits = _
              DimLinearUnitConstants.igDimStyleLinearMeters

            objDimension = objDimensions.AddLength(aLine2d(3))

            objDimension.Constraint = True
            objDimStyle = objDimension.Style
            objDimStyle.PrimaryUnits = _
              DimLinearUnitConstants.igDimStyleLinearMeters

            objDimension = objDimensions.AddDistanceBetweenObjects( _
              aLine2d(1), 0.1, 0.1, 0, False, _
              aLine2d(2), 0, 0.05, 0, False)

            objDimension.Constraint = True
            objDimStyle = objDimension.Style
            objDimStyle.PrimaryUnits = _
              DimLinearUnitConstants.igDimStyleLinearMeters

        Catch ex As Exception
            Console.WriteLine(ex.Message)
        Finally
            OleMessageFilter.Revoke()
        End Try
    End Sub
End Module
Placing Dimensions in C#
Copy Code
using SolidEdgeConstants;
using System;
using System.Reflection;
using System.Runtime.InteropServices;

namespace SolidEdge.SDK
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = null;
            SolidEdgeFramework.Documents documents = null;
            SolidEdgePart.PartDocument part = null;
            SolidEdgePart.ProfileSets profileSets = null;
            SolidEdgePart.ProfileSet profileSet = null;
            SolidEdgePart.Profiles profiles = null;
            SolidEdgePart.Profile profile = null;
            SolidEdgePart.RefPlanes refPlanes = null;
            SolidEdgePart.RefPlane refPlane = null;
            SolidEdgeFrameworkSupport.Lines2d lines2d = null;
            SolidEdgeFrameworkSupport.Line2d[] aLine2d =
              new SolidEdgeFrameworkSupport.Line2d[4];
            SolidEdgeFrameworkSupport.Relations2d relations2d = null;
            SolidEdgeFrameworkSupport.Dimensions dimensions = null;
            SolidEdgeFrameworkSupport.Dimension dimension = null;
            SolidEdgeFrameworkSupport.DimStyle dimStyle = null;

            try
            {
                OleMessageFilter.Register();

                // Connect to a running instance of Solid Edge
                application = (SolidEdgeFramework.Application)
                  Marshal.GetActiveObject("SolidEdge.Application");

                // Get a reference to the documents collection
                documents = application.Documents;

                // Add a Part document
                part = (SolidEdgePart.PartDocument)
                  documents.Add("SolidEdge.PartDocument", Missing.Value);

                // Get a reference to the ref planes collection
                refPlanes = part.RefPlanes;

                // Get a reference to the first reference plane
                refPlane = refPlanes.Item(1);

                // Get a reference to the profile sets collection
                profileSets = part.ProfileSets;

                // Add a new profile set
                profileSet = profileSets.Add();

                // Get a reference to the profiles collection
                profiles = profileSet.Profiles;

                // Add a new profile on the selected reference plane
                profile = profiles.Add(refPlane);

                // Get a reference to the lines 2d collection
                lines2d = profile.Lines2d;

                // Get a reference to the relations 2d collection
                relations2d = (SolidEdgeFrameworkSupport.Relations2d)
                  profile.Relations2d;

                // Get a reference to the dimensions collection
                dimensions = (SolidEdgeFrameworkSupport.Dimensions)
                  profile.Dimensions;

                // Draw the geometry.
                aLine2d[0] = lines2d.AddBy2Points(0, 0, 0.1, 0);
                aLine2d[1] = lines2d.AddBy2Points(0.1, 0, 0.1, 0.1);
                aLine2d[2] = lines2d.AddBy2Points(0.1, 0.1, 0, 0.05);
                aLine2d[3] = lines2d.AddBy2Points(0, 0.05, 0, 0);

                // Add endpoint relationships between the lines
                relations2d.AddKeypoint(
                  aLine2d[0],
                  (int)KeypointIndexConstants.igLineEnd,
                  aLine2d[1],
                  (int)KeypointIndexConstants.igLineStart,
                  Missing.Value);

                relations2d.AddKeypoint(
                  aLine2d[1],
                  (int)KeypointIndexConstants.igLineEnd,
                  aLine2d[2],
                  (int)KeypointIndexConstants.igLineStart,
                  Missing.Value);

                relations2d.AddKeypoint(
                  aLine2d[2],
                  (int)KeypointIndexConstants.igLineEnd,
                  aLine2d[3],
                  (int)KeypointIndexConstants.igLineStart,
                  Missing.Value);

                relations2d.AddKeypoint(
                  aLine2d[3],
                  (int)KeypointIndexConstants.igLineEnd,
                  aLine2d[0],
                  (int)KeypointIndexConstants.igLineStart,
                  Missing.Value);

                // Add dimensions, and change the dimension units to meters
                dimension = dimensions.AddLength(aLine2d[1]);
                dimension.Constraint = true;
                dimStyle = dimension.Style;
                dimStyle.PrimaryUnits = SolidEdgeFrameworkSupport.DimLinearUnitConstants.igDimStyleLinearMeters;

                dimension = dimensions.AddLength(aLine2d[3]);
                dimension.Constraint = true;
                dimStyle = dimension.Style;
                dimStyle.PrimaryUnits = SolidEdgeFrameworkSupport.DimLinearUnitConstants.igDimStyleLinearMeters;

                dimension = dimensions.AddDistanceBetweenObjects(
                  aLine2d[1], 0.1, 0.1, 0, false, aLine2d[2], 0, 0.05, 0, false);
                dimension.Constraint = true;
                dimStyle = dimension.Style;
                dimStyle.PrimaryUnits = SolidEdgeFrameworkSupport.DimLinearUnitConstants.igDimStyleLinearMeters;

            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                OleMessageFilter.Revoke();
            }
        }
    }
}
Dimensions via Variables

When working interactively with the Variable Table, both variables and dimensions are displayed in the table. This enables you to create formulas using the values of dimensions and also have formulas that drive the values of dimensions. In this workflow, there is no apparent difference between variables and dimensions. Internally, however, variables and dimensions are two distinct types of objects that have their own unique collections, properties, and methods.

The Variables collection allows you to work with dimensions in the context of variables through several methods on the collection. These methods include Edit, GetFormula, GetName, PutName, Query, and Translate. The following program uses dimensions through the Variables collection. The following programs assume that Solid Edge is running and in the Profile environment.

See Handling 'Application is Busy' and 'Call was Rejected By Callee' errors for information regarding the use of OleMessageFilter.
Accessing Dimensions through the 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 objProfileSets As SolidEdgePart.ProfileSets = Nothing
        Dim objProfileSet As SolidEdgePart.ProfileSet = Nothing
        Dim objProfiles As SolidEdgePart.Profiles = Nothing
        Dim objProfile As SolidEdgePart.Profile = Nothing
        Dim objVariables As SolidEdgeFramework.Variables = Nothing
        Dim objVariable As Object = Nothing
        Dim objLines2d As SolidEdgeFrameworkSupport.Lines2d = Nothing
        Dim objLine2d As SolidEdgeFrameworkSupport.Line2d = Nothing
        Dim objDimensions As SolidEdgeFrameworkSupport.Dimensions = Nothing
        Dim objDimension1 As SolidEdgeFrameworkSupport.Dimension = Nothing
        Dim objDimension2 As SolidEdgeFrameworkSupport.Dimension = Nothing
        Dim objVariableList As SolidEdgeFramework.VariableList = Nothing
        Dim sName As String
        Dim sFormula As String

        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 active document
            objProfileSets = objPart.ProfileSets

            ' Get a reference to the profile set
            objProfileSet = objProfileSets.Item(objProfileSets.Count)

            ' Get a reference to the profiles collection
            objProfiles = objProfileSet.Profiles

            ' Get a reference to the profile
            objProfile = objProfiles.Item(1)

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

            ' Get a reference to the lines2d collection
            objLines2d = objProfile.Lines2d

            ' Get a reference to the dimensions collection
            objDimensions = objProfile.Dimensions

            ' Create a new line
            objLine2d = objLines2d.AddBy2Points(0, 0, 0.1, 0.1)

            ' Place a dimension on the line to control its length
            objDimension1 = objDimensions.AddLength(objLine2d)

            ' Make the dimension a driving dimension
            objDimension1.Constraint = True

            ' Create a second line
            objLine2d = objLines2d.AddBy2Points(0, 0.1, 0.1, 0.2)

            ' Place a dimension on the line to control its length
            objDimension2 = objDimensions.AddLength(objLine2d)

            ' Make the dimension a driving dimension
            objDimension2.Constraint = True

            ' Assign a name to the dimension placed on the first line
            objVariables.PutName(objDimension1, "Dimension1")

            ' Retrieve the system name of the second dimension, and display
            ' it in the debug window


            sName = objVariables.GetName(objDimension2)
            Console.WriteLine(String.Format("Dimension = {0}", sName))

            ' Edit the formula of the second dimension to be half
            ' the value of the first dimension
            objVariables.Edit(sName, "Dimension1/2.0")

            ' Retrieve the formula from the dimension, and print it to the
            ' debug window to verify
            sFormula = objVariables.GetFormula(sName)
            Console.WriteLine(String.Format("Formula = {0}", sFormula))

            ' This demonstrates the ability to reference a dimension object
            ' by its name
            objDimension1 = objVariables.Translate("Dimension1")

            ' To verify a dimension object was returned, change its
            ' TrackDistance property to cause the dimension to change
            objDimension1.TrackDistance = objDimension1.TrackDistance * 2

            ' Use the Query method to list all all user-defined
            ' variables and user-named Dimension objects and
            ' display in the debug window
            objVariableList = objVariables.Query("*")
            For Each objVariable In objVariableList
                Console.WriteLine(objVariables.GetName(objVariable))
            Next

        Catch ex As Exception
            Console.WriteLine(ex.Message)
        Finally
            OleMessageFilter.Revoke()
        End Try
    End Sub
End Module
Accessing Dimensions through the Variable Table in C#
Copy Code
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;
            SolidEdgePart.ProfileSets profileSets = null;
            SolidEdgePart.ProfileSet profileSet = null;
            SolidEdgePart.Profiles profiles = null;
            SolidEdgePart.Profile profile = null;
            SolidEdgeFramework.Variables variables = null;
            Object oVariable = null;
            SolidEdgeFrameworkSupport.Lines2d lines2d = null;
            SolidEdgeFrameworkSupport.Line2d line2d = null;
            SolidEdgeFrameworkSupport.Dimensions dimensions = null;
            SolidEdgeFrameworkSupport.Dimension dimension1 = null;
            SolidEdgeFrameworkSupport.Dimension dimension2 = null;
            SolidEdgeFramework.VariableList variableList = null;
            String sName;
            String sFormula;

            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 profile sets collection
                profileSets = part.ProfileSets;

                // Get a reference to the profile set
                profileSet = profileSets.Item(profileSets.Count);

                // Get a reference to the profiles collection
                profiles = profileSet.Profiles;

                // Get a reference to the profile
                profile = profiles.Item(1);

                // Get a reference to the variables collection
                variables = (SolidEdgeFramework.Variables)part.Variables;

                // Get a reference to the lines2d collection
                lines2d = profile.Lines2d;

                // Get a reference to the dimensions collection
                dimensions = (SolidEdgeFrameworkSupport.Dimensions)
                  profile.Dimensions;

                // Create a line
                line2d = lines2d.AddBy2Points(0, 0, 0.1, 0.1);

                // Place a dimension on the line to control its length
                dimension1 = dimensions.AddLength(line2d);

                // Make the dimension a driving dimension
                dimension1.Constraint = true;

                // Create a second line
                line2d = lines2d.AddBy2Points(0, 0.1, 0.1, 0.2);

                // Place a dimension on the line to control its length
                dimension2 = dimensions.AddLength(line2d);

                // Make the dimension a driving dimension
                dimension2.Constraint = true;

                // Assign a name to the dimension placed on the first line
                variables.PutName(dimension1, "Dimension1");

                // Retrieve the system name of the second dimension, and display
                // it in the debug window
                sName = variables.GetName(dimension2);
                Console.WriteLine(String.Format("Dimension = {0}", sName));

                // Edit the formula of the second dimension to be half
                // the value of the first dimension
                variables.Edit(sName, "Dimension1/2.0");

                // Retrieve the formula from the dimension, and print it to the
                // debug window to verify
                sFormula = variables.GetFormula(sName);
                Console.WriteLine(String.Format("Formula = {0}", sFormula));

                // This demonstrates the ability to reference a dimension object
                // by its name
                dimension1 = (SolidEdgeFrameworkSupport.Dimension)
                  variables.Translate("Dimension1");

                // To verify a dimension object was returned, change its
                // TrackDistance property to cause the dimension to change
                dimension1.TrackDistance = dimension1.TrackDistance * 2;

                // Use the Query method to list all all user-defined
                // variables and user-named Dimension objects and
                // display in the debug window
                variableList = (SolidEdgeFramework.VariableList)
                  variables.Query("*", null, null, false);

                for (int i = 1; i <= variableList.Count; i++)
                {
                    oVariable = variableList.Item(i);
                    Console.WriteLine(variables.GetName(oVariable));
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                OleMessageFilter.Revoke();
            }
        }
    }
}