Bending Tube simulation

Hey everyone I don’t know if the code will be a challenge for you guys but for me it is. I must simulate a tube bending passing through a specific point in order to know if there will be collisions on the machine. Here is my code, actually I tried only to open any type of tube and by clicking I can move the object through point. NOT A REALLY GOOD IDEA. IM LOOKING FOR A TUBE BENDING CODE OR ANY IDEA FOR DELIVERING THE JOB THANKS IN ADVANCE

The Code NX9:

Option Strict Off
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.Annotations
Imports NXOpen.UF
Imports NXOpen.Utilities

Module componentOriginalPosition

Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim ui As UI = UI.GetUI()
Dim workPart As Part = theSession.Parts.Work

Sub Main()
Dim pt As Point
Dim pt2 As Point
Dim pt3 As point
Dim partLoadStatus1 As PartLoadStatus
Try
Dim openFileDialog1 As New OpenFileDialog()

openFileDialog1.Filter = "Tube file (*.prt)|*.prt|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 1
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = DialogResult.OK Then
Dim BasePoint As Point3d = New Point3d(0.0, 0.0, 0.0)
Dim orientation1 As Matrix3x3
orientation1.Xx = 1.0
orientation1.Xy = 0.0
orientation1.Xz = 0.0
orientation1.Yx = 0.0
orientation1.Yy = 1.0
orientation1.Yz = 0.0
orientation1.Zx = 0.0
orientation1.Zy = 0.0
orientation1.Zz = 1.0

Dim stateArray1(0) As Layer.StateInfo 'Layer 91 Activation
stateArray1(0) = New Layer.StateInfo(91, Layer.State.Selectable)
workPart.Layers.ChangeStates(stateArray1, False)

Dim component1 As Assemblies.Component
component1 = workPart.ComponentAssembly.AddComponent(openFileDialog1.FileName, "SOLID", openFileDialog1.FileName, BasePoint, orientation1, -1, partLoadStatus1, True)

Dim components1(0) As Assemblies.Component
components1(0) = component1
Dim errorList1 As ErrorList
errorList1 = workPart.ComponentAssembly.ReplaceReferenceSetInOwners("Entire Part", components1)

Else : GoTo end3

End If

Catch E As Exception
MessageBox.Show(E.Message)
End Try

Start1:

Dim selComp As NXOpen.Assemblies.Component = Nothing
If SelectComponent(selComp) = Selection.Response.Cancel Then
Exit Sub
End If

Dim response2 As Selection.Response = Selection.Response.Cancel
response2 = select_a_point2(pt2)
If response2 <> Selection.Response.Ok Then Exit Sub
End1:

Start2:

Dim response1 As Selection.Response = Selection.Response.Cancel
response1 = select_a_point(pt)
If response1 <> Selection.Response.Ok Then Exit Sub
Dim Desp As Vector3d
Dim pt3d As Point3d = pt.Coordinates
Dim pt23d As Point3d = pt2.Coordinates

Desp.X = (-pt3d.X + pt23d.X)
Desp.Y = (-pt3d.Y + pt23d.Y)
Desp.Z = (-pt3d.Z + pt23d.Z)

Dim RotMat2 As Matrix3x3
RotMat2.Xx = 1
RotMat2.Xy = 0
RotMat2.Xz = 0
RotMat2.Yx = 0
RotMat2.Yy = 1
RotMat2.Yz = 0
RotMat2.Zx = 0
RotMat2.Zy = 0
RotMat2.Zz = 1
'translate component back to 0,0,0
workPart.ComponentAssembly.MoveComponent(selComp, Desp, RotMat2)

Dim Despv As Vector3d
Desp.X = Despv.X
Desp.Y = Despv.Y
Desp.Z = Despv.Z

End2:
Start3:

' If SelectComponent(selComp) = Selection.Response.Cancel Then
'Exit Sub
'End If
Dim response3 As Selection.Response = Selection.Response.Cancel
response3 = select_a_point3(pt3)
If response3 <> Selection.Response.Ok Then Exit Sub

Dim pt3dv As Point3d = pt3.Coordinates 'Punto3DVariable

Despv.X = 80 '-Despv.X + pt3dv.X
Despv.Y = 60 '-Despv.Y + pt3dv.Y
Despv.Z = 30 '-Despv.Z + pt3dv.Z

Dim RotMat3 As Matrix3x3
RotMat2.Xx = 1
RotMat2.Xy = 0
RotMat2.Xz = 0
RotMat2.Yx = 0
RotMat2.Yy = 1
RotMat2.Yz = 0
RotMat2.Zx = 0
RotMat2.Zy = 0
RotMat2.Zz = 1
'translate component back to 0,0,0
workPart.ComponentAssembly.MoveComponent(selComp, Despv, RotMat3)
Dim resp As Integer
resp = ui.NXMessageBox.Show("Question", NXMessageBox.DialogType.Question, "Do you want to continue?")
If resp = 1 Then GoTo Start3
End3:

End Sub
Function SelectComponent(ByRef selObj As TaggedObject) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim message As String = "Select component to reset position"
Dim title As String = "Select a Component"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_component_type
.Subtype = UFConstants.UF_all_subtype
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(message, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Public Function select_a_point(ByRef pt As Point) As Selection.Response
Dim mask(0) As Selection.MaskTriple
With mask(0)
.Type = UFConstants.UF_point_type
.Subtype = 0
.SolidBodySubtype = 0
End With
Dim cursor As Point3d = Nothing
ufs.Ui.SetCursorView(0)
ufs.Ui.LockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
Dim resp As Selection.Response = _
ui.SelectionManager.SelectObject("Select P1 Of The Tube", "Select P1 Of The Tube", _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, mask, pt, cursor)
ufs.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
ElseIf resp = Selection.Response.Back Then
Return Selection.Response.Back
Else
Return Selection.Response.Cancel
End If
End Function
Public Function select_a_point2(ByRef pt2 As Point) As Selection.Response
Dim mask(0) As Selection.MaskTriple
With mask(0)
.Type = UFConstants.UF_point_type
.Subtype = 0
.SolidBodySubtype = 0
End With
Dim cursor As Point3d = Nothing
ufs.Ui.SetCursorView(0)
ufs.Ui.LockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
Dim resp As Selection.Response = _
ui.SelectionManager.SelectObject("Select Origin Point For Location", "Select Origin Point For Location", _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, mask, pt2, cursor)
ufs.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
ElseIf resp = Selection.Response.Back Then
Return Selection.Response.Back
Else
Return Selection.Response.Cancel
End If
End Function
Public Function select_a_point3(ByRef pt3 As Point) As Selection.Response
Dim mask(0) As Selection.MaskTriple
With mask(0)
.Type = UFConstants.UF_point_type
.Subtype = 0
.SolidBodySubtype = 0
End With
Dim cursor As Point3d = Nothing
ufs.Ui.SetCursorView(0)
ufs.Ui.LockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
Dim resp As Selection.Response = _
ui.SelectionManager.SelectObject("In order to continue", "Select next point", _
Selection.SelectionScope.AnyInAssembly, _
Selection.SelectionAction.ClearAndEnableSpecific, _
False, False, mask, pt3, cursor)
ufs.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
ElseIf resp = Selection.Response.Back Then
Return Selection.Response.Back
Else
Return Selection.Response.Cancel
End If
End Function
End Module