Combining two codes (transferred)

Forums: 

Here's a slightly tidier version of the code. Posted here since it uses SNAP functions extensively:

Option Infer On
Imports Snap, Snap.Create, Snap.Math

Public Class MyProgram : Inherits UI.BlockForm

' Declarations of the blocks on a MyProgram dialog
Dim BlockLineX As UI.Block.SelectObject
Dim BlockLineY As UI.Block.SelectObject
Dim BlockLineZ As UI.Block.SelectObject

Dim BlockArc1 As UI.Block.SelectObject
Dim BlockArc2 As UI.Block.SelectObject

' Constructor for a MyProgram dialog object
Public Sub New()

Me.Title = "Select Curves" ' Text to be shown in title bar of dialog
Me.Cue = "Please select lines and arcs" ' Text to be shown in cue line

' Create three blocks to select lines
BlockLineX = CreateSelectLineBlock("Linex")
BlockLineY = CreateSelectLineBlock("Liney")
BlockLineZ = CreateSelectLineBlock("Linez")

' Create two blocks to select arcs
BlockArc1 = CreateSelectArcBlock("Arc1")
BlockArc2 = CreateSelectArcBlock("Arc2")

' Add all the blocks to the BlockForm
Me.AddBlocks(BlockLineX, BlockArc1, BlockLineY, BlockArc2, BlockLineZ)

End Sub

Public Shared Sub Main()

' Create and display a MyProgram dialog
Dim myForm = New MyProgram()
myForm.Show()

End Sub

Public Overrides Sub OnApply()
Dim lineX As NX.Line = BlockLineX.SelectedObjects(0)
Dim lineY As NX.Line = BlockLineY.SelectedObjects(0)
Dim lineZ As NX.Line = BlockLineZ.SelectedObjects(0)

Dim arc1 As NX.Arc = BlockArc1.SelectedObjects(0)
Dim arc2 As NX.Arc = BlockArc2.SelectedObjects(0)

Dim len1 = lineX.ArcLength : InfoWindow.WriteLine(" L1 = " & len1.ToString)
Dim p1 = lineX.StartPoint : InfoWindow.WriteLine(" P1 = " & p1.ToString)
Dim p1x = p1.X : InfoWindow.WriteLine("PX1 = " & p1x.ToString)

Dim len2 = arc1.ArcLength : InfoWindow.WriteLine(" L2 = " & len2.ToString)
Dim r2 = arc1.Radius : InfoWindow.WriteLine(" R2 = " & r2.ToString)

Dim len3 = lineY.ArcLength : InfoWindow.WriteLine(" L3 = " & len3.ToString)
Dim p3 = lineY.StartPoint : InfoWindow.WriteLine(" P3 = " & p3.ToString)
Dim p3x = p3.X : InfoWindow.WriteLine("PX3 = " & p3x.ToString)

Dim len4 = arc2.ArcLength : InfoWindow.WriteLine(" L4 = " & len4.ToString)
Dim r4 = arc2.Radius : InfoWindow.WriteLine(" R4 = " & r4.ToString)

Dim len5 = lineZ.ArcLength : InfoWindow.WriteLine(" L5 = " & len5.ToString)
Dim p5 = lineZ.StartPoint : InfoWindow.WriteLine(" P5 = " & p5.ToString)
Dim p5x = p5.X : InfoWindow.WriteLine("PX5 = " & p5x.ToString)

InfoWindow.WriteLine("")

' Do the geometry construction

Dim a = len1
Dim b = len3
Dim c = len5
Dim d = len2
Dim e = len4

Dim X1 = p1x + 0.5 * a : InfoWindow.WriteLine("X1 = " & X1.ToString)
Dim X2 = (p1x - (p1x / 180)) : InfoWindow.WriteLine("X2 = " & X2.ToString)
Dim X3 = p3x : InfoWindow.WriteLine("X3 = " & X3.ToString)
Dim X4 = (p3x - (p3x / 180)) : InfoWindow.WriteLine("X4 = " & X4.ToString)
Dim X5 = p5x + 0.5 * c : InfoWindow.WriteLine("X5 = " & X5.ToString)

Dim Xt As Double = ( a*X1 + b*X3 + c*X5 + d*X2 + e*X4 ) / (a + b + c + d + e)
InfoWindow.WriteLine("XT = " & Xt.ToString)

Dim d11 As Double = 2 * System.Math.Sqrt(2 * (a + b + c + d + e))
InfoWindow.WriteLine("Diameter = " & d11.ToString)

Dim f As NX.Cylinder = Cylinder({0, 0, 0}, Vector.AxisZ, 1, 4 * d11)

End Sub

' Create a block for selecting a line
Private Function CreateSelectLineBlock(label As String) As UI.Block.SelectObject
Dim myBlock = New UI.Block.SelectObject
myBlock.LabelString = label
myBlock.SetFilter(Snap.NX.ObjectTypes.Type.Line)
myBlock.MaximumScope = UI.Block.SelectionScope.AnyInAssembly
Return myBlock
End Function

' Create a block for selecting an arc
Private Function CreateSelectArcBlock(label As String) As UI.Block.SelectObject
Dim myBlock = New UI.Block.SelectObject
myBlock.LabelString = label
myBlock.SetFilter(Snap.NX.ObjectTypes.Type.Arc)
myBlock.MaximumScope = UI.Block.SelectionScope.AnyInAssembly
Return myBlock
End Function

End Class

Moving this discussion into the SNAP forum was a good idea; I moved the original question as well. It can be found here:
http://www.nxjournaling.com/content/combining-two-codes