Monday 22 September 2014

Match Properties for Solid Edge - Part 3

...continued from Part 2

The currently open document is checked if it is of Draft type. If it is not then an error message is displayed.

If Not TypeOf oDoc Is SolidEdgeDraft.DraftDocument Then
  MessageBox.Show("A Draft document should be open.", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Error)
  Me.Close()

If the document is indeed of Draft type, the currently selected object is stored in a selection set.

Else
  oSSetSource = oDoc.SelectSet

oSSetSource is a variable of type SelectSet which stores one or more currently selected objects. Even when there are no objects selected, the SelectSet collection exists, with a count of 0.

Dim oSSetSource As SolidEdgeFramework.SelectSet

Other required variables for the program are declared as below:

oSSetDestination for storing objects to which the properties will be matched.

Dim oSSetDestination As SolidEdgeFramework.SelectSet

oSource and oDestin store a single object from the selection sets at source and destination.

Dim oSource As Object
Dim oDestin As Object

We want to match four properties from the source to destination viz. the Layer, Color, Line width and the Line type. The variables to store these are as below:

Dim sLayer As String
Dim iColor As Integer
Dim dWidth As Double
Dim sLtype As String

There can be only one source object. So the selection set is checked accordingly:

If oSSetSource.Count > 1 Then
  MessageBox.Show("Select only one source object.", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  Me.Close()
ElseIf oSSetSource.Count <= 0 Then
  MessageBox.Show("Select a source object first.", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  Me.Close()

If the count of selected objects when the Form loads is greater than 1, the user is informed accordingly and the program terminates: Me.Close()

Also if no object is selected i.e. the count is 0 the program terminates too after displaying a message.

Further, if it is found that only one object was selected, the type of the selected object is checked as below and its 4 properties are stored in the respective variables:

ElseIf oSSetSource.Count = 1 Then
  oSource = oSSetSource.Item(1)
    If TypeOf oSource Is SolidEdgeFrameworkSupport.Line2d Or _
      TypeOf oSource Is SolidEdgeFrameworkSupport.Arc2d Or _
      TypeOf oSource Is SolidEdgeFrameworkSupport.Circle2d Or _
      TypeOf oSource Is SolidEdgeFrameworkSupport.Ellipse2d Or _
      TypeOf oSource Is SolidEdgeFrameworkSupport.EllipticalArc2d Or _
      TypeOf oSource Is SolidEdgeFrameworkSupport.BSplineCurve2d Or _
      TypeOf oSource Is SolidEdgeFrameworkSupport.Point2d Then
        sLayer = oSource.Layer
        iColor = oSource.Style.LinearColor
        dWidth = oSource.Style.Width
        sLtype = oSource.Style.DashName

Finally if the source object is not one of the allowed types, the program terminates again.

Else
  MessageBox.Show("Not a valid source object.", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  Me.Close()
End If

Continued to Part 4...

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

No comments:

Post a Comment