CAM: User Defined Tools

Hi,

Does anyone have any experiance with creating user defined milling tools with the journal. My code should create a tool with custom form, but instead it creates a new tool and uses the standard new tool profile, like my lines of code arn't there.

The journal runs fine other than this, so it must understand what I have done?

Thanks for any help,

' NX 7.5.5.4
'
Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports System.Windows.Forms

Module NXJournal
Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

Dim file As String
Dim OpenFileDialog1 As New OpenFileDialog()

If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
file = OpenFileDialog1.FileName
Else
Exit Sub
End If

Dim txt_name As String = "test"
Dim type As String
Dim length_txt As String
Dim angle_txt As String
Dim length As Double
Dim angle As Double
Dim radius As String
Dim sweep As Double
Dim sr As New System.IO.StreamReader(file)

theSession.CleanUpFacetedFacesAndEdges()

Dim nCGroup1 As CAM.NCGroup = CType(workPart.CAMSetup.CAMGroupCollection.FindObject("A55"), CAM.NCGroup)

Dim nCGroup2 As CAM.NCGroup
nCGroup2 = workPart.CAMSetup.CAMGroupCollection.CreateTool(nCGroup1, "mill_planar_metric_NX75/A", "MILL_USER_DEFINED", CAM.NCGroupCollection.UseDefaultName.False, txt_name)

Dim tool1 As CAM.Tool = CType(nCGroup2, CAM.Tool)

Dim millFormToolBuilder1 As CAM.MillFormToolBuilder
millFormToolBuilder1 = workPart.CAMSetup.CAMGroupCollection.CreateMillFormToolBuilder(tool1)

millFormToolBuilder1.Segments.Delete(2)
millFormToolBuilder1.Segments.Delete(1)
millFormToolBuilder1.Segments.Delete(0)

Dim i As Integer = 1
Dim line As String

While sr.EndOfStream = False
line = sr.ReadLine()
If line = "Information on object # " & i Then
i = i + 1
Else
End If
End While

sr.BaseStream.Seek(0, SeekOrigin.Begin)
sr.DiscardBufferedData()

Dim ii As int32 = 0
Dim newitemindex1 As Integer

Do
Do
line = sr.ReadLine()
Loop Until line = "Information on object # " & (ii + 1)
type = sr.ReadLine()

If type = "Line" Then

angle_txt = sr.ReadLine()
angle_txt = Replace(angle_txt, "Angle = ", "")
angle_txt = Replace(angle_txt, "Angle = ", "")
angle_txt = Replace(angle_txt, "Angle = ", "")
length_txt = sr.ReadLine()
length_txt = Replace(length_txt, "Length = ", "")
length_txt = Replace(length_txt, "Length = ", "")
length_txt = Replace(length_txt, "Length = ", "")

If Double.TryParse(angle_txt, angle) Then
Else
End If

If Double.TryParse(length_txt, length) Then
Else
End If

newitemindex1 = millFormToolBuilder1.Segments.CreateWithParameter(length, angle, 0, 0)
millFormToolBuilder1.Segments.ModifyWithParameter(ii, length, angle, 0, 0)

ElseIf type = "Arc" Then

sr.ReadLine()
radius = sr.ReadLine()
sr.ReadLine()
sweep = sr.ReadLine()

If angle = "" Then
angle = 0.0
Else
End If

newitemindex1 = millFormToolBuilder1.Segments.CreateWithParameter(0, angle, radius, sweep)
millFormToolBuilder1.Segments.ModifyWithParameter(ii, 0, angle, radius, sweep)

End If

ii = ii + 1

Loop Until ii = (i - 1)

sr.Close()

End Sub
End Module

Incase anyone needs this in future, you need;

Imports NXOpen.CAM
Imports NXOpen.Utilities

and after the create with parameter code

millFormToolbuilder1.Commit

Dave

Cheers,

David