Sunday 19 October 2014

Rectangle Centerlines Part 08

...continued from Part 7

The centerlines are added between mid points of opposite lines of the rectangle viz. between 1st & 3rd and 2nd and 4th lines.

oCenterLine1 = oActiveSketch.Lines2d.AddBy2Points(dL1_MidX, dL1_MidY, dL3_MidX, dL3_MidY)

oCenterLine2 = oActiveSketch.Lines2d.AddBy2Points(dL2_MidX, dL2_MidY, dL4_MidX, dL4_MidY)

If the Create Relationships check box is checked ON, the relations between the  centerlines and the lines in the selection set are created as below:

If chkRelations.Checked = True Then
  oRels2D.AddKeypoint(oLine1, KeypointIndexConstants.igLineStart, oCenterLine1, KeypointIndexConstants.igLineStart)
  oRels2D.AddKeypoint(oLine3, KeypointIndexConstants.igLineStart, oCenterLine1, KeypointIndexConstants.igLineEnd)

  oRels2D.AddKeypoint(oLine1, KeypointIndexConstants.igLineEnd, oCenterLine2, KeypointIndexConstants.igLineStart)
  oRels2D.AddKeypoint(oLine3, KeypointIndexConstants.igLineEnd, oCenterLine2, KeypointIndexConstants.igLineEnd)
End If


The first relation is created between line1's midpoint and centerline1's start point.

The second relation is created between line3's midpoint and centerline1's end.

The third relation is created between line2's midpoint and centerline2's start.

The fourth relation is created between line4's midpoint and centerline2's end.

This is followed by setting the LineType of the centerlines to Chain i.e. Dash-dot:

oCenterLine1.Style.DashName = "Chain"
oCenterLine2.Style.DashName = "Chain"

After this the color of centerlines is set to the one picked from the color dialog.

oCenterLine1.Style.LinearColor = seColor
oCenterLine2.Style.LinearColor = seColor

The ColorDialog control returns a System.Drawing.Color which cannot be applied to Solid Edge objects directly.

In the color buttons Click event, the system color picked by user is converted to Solid Edge color integer as below:

Private Sub btnColor_Click(sender As System.Object, e As System.EventArgs) Handles btnColor.Click
    dColor.AllowFullOpen = True
    dColor.AnyColor = True
    Dim cColor As System.Drawing.Color = dColor.Color
    btnColor.BackColor = dColor.Color
    seColor = ColorTranslator.ToWin32(cColor)
End Sub

Finally the Layer of the centerlines in the Draft mode is set as below:

Dim oLayer As Layer = Nothing

If oApp.ActiveDocument.Type = SolidEdgeFramework.DocumentTypeConstants.igDraftDocument Then
  Select Case layerOption
    Case CenterLineLayerOption.SameAsRectangle
      oLayer = oSheet.Layers.Item(oLine1.Layer)

    Case CenterLineLayerOption.ExistingLayer
      oLayer = oSheet.Layers.Item(lstLayers.SelectedItem.ToString)

    Case CenterLineLayerOption.NewLayer
      oLayer = oSheet.Layers.Add(txtLayer.Text.Trim)
End Select

First the layerOption value is checked. This value is set from the radio buttons on the Form.

If the layer option is SameAsRectangle, oLine1's layer if first acquired and this item is searched in the Layers collection of the active sheet in the Draft document:

oLayer = oSheet.Layers.Item(oLine1.Layer)

If the layer option is ExistingLayer, the layer is set from the list lstLayers that was flooded during Form Load.

oLayer = oSheet.Layers.Item(lstLayers.SelectedItem.ToString)

If the layer option is NewLayer, a new layer is created on-the-fly with a name specified in the text box:

oLayer = oSheet.Layers.Add(txtLayer.Text.Trim)

An additional check is provided in the Click event of the btnCreate button:

If txtLayer.Text = String.Empty Then
  MessageBox.Show("Layer name cannot be left blank.", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  Exit Sub
End If

The layer is then finally assigned to the centerlines:

oCenterLine1.Layer = oLayer.Name
oCenterLine2.Layer = oLayer.Name

Similarly, support for Assembly and Sheetmetal documents too can be easily added using the source code provided below.

save Download just the program or executable file.

save Download the VB.Net (VS 2010, .Net 4.0) solution files.

Some other interesting Solid Edge commands you can learn to make are:

1. Match Properties or Format Painter.

2. Purge Variables - i.e. delete un-used variables.

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

No comments:

Post a Comment