Tuesday, 14 October 2014

Rectangle Centerlines Part 03

...continued from Part 2

The UI discussed in last part does not appear until several checks as below are passed:

  1. Solid edge should be running.
  2. A document should be open.
  3. The open document should be either a Part or Draft only.
  4. In case of Part document, the sketcher environment should be active.

Some Form level variables are as below:

Public Class Form1

oApp to store the Solid Edge Application:
    Dim oApp As SolidEdgeFramework.Application

oDoc to store the Solid Edge Document:
    Dim oDoc As SolidEdgeDocument

oDocD stores the Draft document:

    Dim oDocD As SolidEdgeDraft.DraftDocument

oDocP stores the Part document:

    Dim oDocP As SolidEdgePart.PartDocument

oSelectSet stores the selection set that holds the rectangle lines picked by user:

    Dim oSelectSet As SolidEdgeFramework.SelectSet

oUoM for the Units of Measure object which helps in expressing values in document units i.e. mm or inch:
    Dim oUoM As UnitsOfMeasure

oSheet stores the active sheet in the Draft document:
    Dim oSheet As Sheet = Nothing

seColor for the color of centerlines:

    Dim seColor As Integer

The cLineMode variable can have one of two values defined in an Enum CenterLineMode:

    Dim cLineMode As CenterLineMode = CenterLineMode.ThroughMidPoints

Private Enum CenterLineMode
    ThroughMidPoints = 1
    ThroughCornerPoints = 2
End Enum

The value for cLineMode variable is stored from the radio button for the centerline type or by clicking the images.

Private Sub radCorners_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles radCorners.CheckedChanged
  cLineMode = CenterLineMode.ThroughCornerPoints
End Sub

and also via the image when clicked:

Private Sub picCorners_Click(sender As System.Object, e As System.EventArgs) Handles picCorners.Click
  cLineMode = CenterLineMode.ThroughCornerPoints
  radCorners.Checked = True
End Sub

Similarly, layerOption is also an Enum as defined below:

    Dim layerOption As CenterLineLayerOption = CenterLineLayerOption.SameAsRectangle

Private Enum CenterLineLayerOption
    SameAsRectangle = 1
    NewLayer = 2
    ExistingLayer = 3
End Enum

Finally, the string sTitle is used as a caption or title for all message boxes used througout the program.

    Const sTitle As String = "Rectangle Centerlines"

In the Form's Load event, first the centerline mode and layer option modes are set in sync with the status of the radio buttons for these on the Form:

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

  cLineMode = CenterLineMode.ThroughMidPoints
  layerOption = CenterLineLayerOption.SameAsRectangle

  oApp = Marshal.GetActiveObject("SolidEdge.Application")
  If oApp Is Nothing Then
    MessageBox.Show("Solid Edge should be running.", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Information)
    End
  End If

Try to connect to Solid Edge failing which a message is displayed and the program is put to an End.

This should not be a problem if you are running this macro from a button on the ribbon.

Continued in Part 4...

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