Saturday 18 October 2014

Rectangle Centerlines Part 07

...continued from Part 6

Another validation that is good to have is checking if two lines from the selection set are each vertical and horizontal. This check however won't affect the centerline creation and would still create the centerlines as below:

16

Yet another important check to be made would be: lines being connected in order or sequence or end-to-end i.e. the end point of first line is connected to the start point of next line.

This is important since the order of the lines drawn or picked is as below, the results may not be as desired:

17

If the rectangle has been drawn with any of the Solid Edge's Rectangle commands, the centerlines will always be drawn correctly.

The Draw Centerlines button calls the function with same name which takes the validated selection set as an argument and simply stores the 4 lines in respective variables:

Private Sub DrawCenterlines(ByVal oSelectSet As SelectSet)
  Dim oLine1 As Line2d = oSelectSet.Item(1)
  Dim oLine2 As Line2d = oSelectSet.Item(2)
  Dim oLine3 As Line2d = oSelectSet.Item(3)
  Dim oLine4 As Line2d = oSelectSet.Item(4)

  Dim oCenterLine1 As Line2d = Nothing
  Dim oCenterLine2 As Line2d = Nothing

Also variables for the two centerlines are declared as above.

This is followed by extracting the coordinates of the start and end points of all lines in the selection set:

Dim dL1_StartX As Double = 0 : Dim dL1_StartY As Double = 0
oLine1.GetStartPoint(dL1_StartX, dL1_StartY)

Dim dL1_EndX As Double = 0 : Dim dL1_EndY As Double = 0
oLine1.GetEndPoint(dL1_EndX, dL1_EndY)

Dim dL3_StartX As Double = 0 : Dim dL3_StartY As Double = 0
oLine3.GetStartPoint(dL3_StartX, dL3_StartY)

Dim dL3_EndX As Double = 0 : Dim dL3_EndY As Double = 0
oLine3.GetEndPoint(dL3_EndX, dL3_EndY)

Then the active document is checked if it is Part or Draft.

In case of Part, the ActiveSketch and the Relations collection are stored.

If cLineMode = CenterLineMode.ThroughCornerPoints Then
  If oApp.ActiveDocument.Type = SolidEdgeFramework.DocumentTypeConstants.igPartDocument Then
    oActiveSketch = oDocP.ActiveSketch
    oRels2D = oActiveSketch.Relations2d

    oCenterLine1 = oActiveSketch.Lines2d.AddBy2Points(dL1_StartX, dL1_StartY, dL3_StartX, dL3_StartY)
    oCenterLine2 = oActiveSketch.Lines2d.AddBy2Points(dL1_EndX, dL1_EndY, dL3_EndX, dL3_EndY)
  End If

The first centerline is drawn from start of first line to start of third line as illustrated below:

18

Similarly the second centerline is drawn from end point of line 1 to end point of line 3.

In case of Draft document, the relations belong to the active sheet and the centerlines are drawn into the Sheet's Lines2D collection:

If oApp.ActiveDocument.Type = SolidEdgeFramework.DocumentTypeConstants.igDraftDocument Then
  oSheet = oDocD.ActiveSheet
  oRels2D = oSheet.Relations2d

  oCenterLine1 = oSheet.Lines2d.AddBy2Points(dL1_StartX, dL1_StartY, dL3_StartX, dL3_StartY)
  oCenterLine2 = oSheet.Lines2d.AddBy2Points(dL1_EndX, dL1_EndY, dL3_EndX, dL3_EndY)
End If

If the centerline mode is ThroughMidPoints, the mid points of all 4 lines are calculated as below:

19

Dim dL1_MidX As Double = 0 : Dim dL1_MidY As Double = 0
dL1_MidX = (dL1_StartX + dL1_EndX) / 2.0
dL1_MidY = (dL1_StartY + dL1_EndY) / 2.0

Continued to Part 8...

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


No comments:

Post a Comment