cancel
Showing results for 
Search instead for 
Did you mean: 

Get the value of GetTaperedShankLength(millToolBuilder)

Genius
Genius

Hello,

 

I have a script that starts Vericut and checks the tool lengths in NX to that of the ones in Vericut but now that the there is the shank option in the tool definition I am getting errors with the lengths I know that this due to the script not reading the shank length, with my very limited .VB knowledge I can't get it incorporate this in the argument so I was hoping that someone could point me in the right direction?

 

Below is the snippet of code and I have added what I thought might work but hasn't?

 

Public Function CheckTool(ByVal _toolTag As Tag, ByVal _requestType As Integer)
        'Get tool ATMS reference & Gauge Length
        Dim nxTool As CAM.Tool = NXObjectManager.Get(_toolTag)
        Dim millToolBuilder As CAM.MillToolBuilder = workPart.CAMSetup.CAMGroupCollection.CreateMillToolBuilder(nxTool)
  Dim atmsNo As String = ""
        Dim atmsNo1 As String = Replace(UCase(Trim(millToolBuilder.TlCtlgNum)), " ", "")
  If  atmsNo1 = "" Then
   atmsNo1 = "XXXXX"
  End If
  Dim atmsNo2 As String = UCase(Trim(millToolBuilder.TlDescription))
     Dim match As Match = Regex.Match(atmsNo1, "([A-Z]\d{3}.*)")
  If match.Success Then
   atmsNo = match.Groups(0).Value
  ElseIf Len(atmsNo2) > 0 Then
   Dim match2 As Match = Regex.Match(atmsNo2, "\(([A-Z]\d{3}.*)\)")
   If match2.Success Then
    atmsNo = match2.Groups(1).Value
   End If
  Else
   Dim match3 As Match = Regex.Match(atmsNo1, "(BN\d*)")
   If match3.Success Then
    atmsNo = match3.Groups(1).Value
   End If    
  End If
        Dim toolNo As String = millToolBuilder.TlNumberBuilder.Value
       
        If atmsNo = "" Then
          msgBox("Tool " & toolNo & " does not have an ATMS number.")
          Return False
        End If
        If _requestType = 1 Then
            If Not toolList.Contains(atmsNo) Then
             'CHECK TOOLNO HASN'T ALREADY BEEN USED FOR ANOTHER TOOL
             If toolList.ContainsValue(toolNo) Then
              msgBox("Tool ID: " & toolNo & " Assigned to multiple tools. Simulation Aborted. Please correct.")
              abortFlag = True
              Return False
             End If
                toolList.Add(atmsNo, toolNo)
                Return True
            Else
                toolList(atmsNo) = toolList(atmsNo) & "," & toolNo
                'msgBox("Duplicate ATMS No. for Tool " & toolNo & " (" & nxTool.Name & ")")
               Return True
            End If
        End If
            Dim holderLength As Double = GetHolderLength(millToolBuilder)
            If holderLength < 0 Then
                msgBox("Cannot retrieve holder length for tool " & nxTool.Name)
                CheckTool = False
                Exit Function
            End If
            Dim cutterLength As Double = GetCutterLength(nxTool.Tag)
            If cutterLength <= 0 Then
                msgBox("Cannot retrieve cutter length for tool " & nxTool.Name)
                CheckTool = False
                Exit Function
            End If
   Dim shankLength As Double = GetTaperedShankLength(millToolBuilder)
            If ShankLength < 0 Then
                msgBox("Cannot retrieve holder length for tool " & nxTool.Name)
                CheckTool = False
                Exit Function
            End If
            'Check tool is valid
            If holderLength >= 0 And cutterLength > 0 ShankLength >= 0 Then
                'Holder length already accounts for cutter offset distance within the holder
                Dim gaugeLength As Double = holderLength + cutterLength + shanklength

                'Get Vericut Tool Length
                Dim vLength As Double = GetVLength(toolNo)
                'Check Lengths Match
                If gaugeLength <> vLength Then
                    lengthWarnings &= nxTool.Name & " (" & atmsNo & ") [" & gaugeLength & ":" & vLength & "]" & vbCrLf
                End If
                'msgBox(nxTool.Name & " (" & atmsNo & ") : " & gaugeLength.ToString())
            Else
                unKnownWarnings &= nxTool.Name & " (" & atmsNo & ")" & vbCrLf
                msgBox("Cannot retrieve holder and/or cutter data")
                CheckTool = False
            End If
            CheckTool = True
    End Function
    Public Function GetHolderLength(ByRef millToolBuilder As CAM.MillToolBuilder)
        Dim hSectionBuilder As CAM.HolderSectionBuilder = millToolBuilder.HolderSectionBuilder
        Dim holderLength As Double = 0
        Dim sectionCount As Integer = hSectionBuilder.NumberOfSections
        holderLength -= hSectionBuilder.TlHolderOffsetBuilder.Value
        For i As Integer = 0 To sectionCount - 1
            Dim hSection As NXObject = hSectionBuilder.GetSection(i)
            Dim hDia As Double
            Dim hLength As Double
            Dim hTaper As Double
            Dim hCornerRadius As Double
            hSectionBuilder.Get(hSection, hDia, hLength, hTaper, hCornerRadius)
            holderLength += hLength
        Next
        GetHolderLength = holderLength
    End Function
    Public Function GetCutterLength(ByRef _toolTag As Tag)
        Dim nxType As Integer
        Dim nxSubtype As Integer
        Dim tipAngle As Double
        Dim taperAngle As Double
        Dim Length As Double
  Dim shankLength As Double
        Dim diameter As Double
        Dim cornerRad1 As Double
        Dim cornerX1 As Double
        Dim cornerY1 As Double
        Dim cornerRad2 As Double
        Dim cornerX2 As Double
        Dim cornerY2 As Double
        Dim shakDia As Double
        Dim fluteLength As Double
        Dim teeth As Integer
        length = 0
        Dim cBuilder As CAM.Tool = NXObjectManager.Get(_toolTag)
        theUFSession.Cutter.AskTypeAndSubtype(_toolTag, nxType, nxSubtype)
        Select Case nxType
            Case UFConstants.UF_CUTTER_TYPE_MILL 'MILL, FACE_MILL, 7_PARAM, 10_PARAM, SPOT_FACING, COUNTER_BORE, COUNTER_SINK
                Dim toolBuilder As MillToolBuilder = workPart.CAMSetup.CAMGroupCollection.CreateMillToolBuilder(cBuilder)
             length = toolBuilder.TlHeightBuilder.Value
    shankLength = toolBuilder.T1TaperedShankLengthBuilder.Value
                'tipAngle = toolBuilder.TlTipAngBuilder.Value
                'taperAngle = toolBuilder.TlTaperAngBuilder.Value
                'diameter = toolBuilder.TlDiameterBuilder.Value
                'cornerRad1 = toolBuilder.TlCor1RadBuilder.Value
                'cornerX1 = toolBuilder.TlXcenCor1Builder.Value
                'cornerY1 = toolBuilder.TlYcenCor1Builder.Value
                'cornerRad2 = toolBuilder.TlCor2RadBuilder.Value
                'cornerX2 = toolBuilder.TlXcenCor2Builder.Value
                'cornerY2 = toolBuilder.TlYcenCor2Builder.Value
                'shankDia = toolBuilder.TlShankDiaBuilder.Value
                'fluteLength = toolBuilder.TlFluteLnBuilder.Value
                'teeth = toolBuilder.TlNumFlutesBuilder.Value
    'shankLength = toolBuilder.T1TaperedShankLengthBuilder.Value
            Case UFConstants.UF_CUTTER_TYPE_DRILL 'DRILL TOOL
                If nxSubType = UFConstants.UF_CUTTER_SUBTYPE_DRILL_TAP Then
                    Dim toolBuilder As DrillTapToolBuilder = workPart.CAMSetup.CAMGroupCollection.CreateDrillTapToolBuilder(cBuilder)
                    length = toolBuilder.TlHeightBuilder.Value
     shankLength = toolBuilder.T1TaperedShankLengthBuilder.Value
                    'params("MajorDiameter") = toolBuilder.TlDiameterBuilder.Value
                    'params("MinorDiameter") = toolBuilder.TlDiameterBuilder.Value - (0.86603 * toolBuilder.TlPitchBuilder.Value)
                    'params("ThreadPerUnit") = 1 / toolBuilder.TlPitchBuilder.Value
                    'params("ThreadLength") = toolBuilder.TlFluteLnBuilder.Value
                    'params("NeckDiameter") = toolBuilder.TlShankDiaBuilder.Value
                    'params("NeckLength") = params("OverallLength") * 0.6
                    'shankDia = toolBuilder.TlShankDiaBuilder.Value / 0.7
                    'fluteLength = toolBuilder.TlFluteLnBuilder.Value
                    'cutterLength = params("OverallLength")
                    'teeth = toolBuilder.TlNumFlutesBuilder.Value
     'shankLength = toolBuilder.T1TaperedShankLengthBuilder.Value
                Else
                    Dim toolBuilder As DrillToolBuilder = workPart.CAMSetup.CAMGroupCollection.CreateDrillStdToolBuilder(cBuilder)
     length = toolBuilder.TlHeightBuilder.Value
     shankLength = toolBuilder.T1TaperedShankLengthBuilder.Value
                    'params("A") = (180 - toolBuilder.TlPointAngBuilder.Value) / 2
                    'params("B") = toolBuilder.TlTaperAngBuilder.Value
                    'params("D") = toolBuilder.TlDiameterBuilder.Value
                    'shankDia = toolBuilder.TlShankDiaBuilder.Value
                    'fluteLength = toolBuilder.TlFluteLnBuilder.Value
                    'cutterLength = params("H")
                    'teeth = toolBuilder.TlNumFlutesBuilder.Value
     'shankLength = toolBuilder.T1TaperedShankLengthBuilder.Value
                End If
            Case UFConstants.UF_CUTTER_TYPE_THREAD
                Dim toolBuilder As DrillThreadMillToolBuilder = workPart.CAMSetup.CAMGroupCollection.CreateDrillThreadMillToolBuilder(cBuilder)
    length = toolBuilder.TlHeightBuilder.Value
    shankLength = toolBuilder.T1TaperedShankLengthBuilder.Value
                'params("MajorDiameter") = toolBuilder.TlDiameterBuilder.Value
                'params("MinorDiameter") = toolBuilder.TlDiameterBuilder.Value - (0.86603 * toolBuilder.TlPitchBuilder.Value)
                'params("ThreadPerUnit") = 1 / toolBuilder.TlPitchBuilder.Value
                'params("ThreadLength") = toolBuilder.TlFluteLnBuilder.Value
                'params("NeckDiameter") = toolBuilder.TlShankDiaBuilder.Value
                'params("NeckLength") = params("OverallLength") * 0.6
                'shankDia = toolBuilder.TlShankDiaBuilder.Value / 0.7
                'fluteLength = toolBuilder.TlFluteLnBuilder.Value
                'cutterLength = params("OverallLength")
                'teeth = toolBuilder.TlNumFlutesBuilder.Value
    'shankLength = toolBuilder.T1TaperedShankLengthBuilder.Value
            Case UFConstants.UF_CUTTER_TYPE_TURN 'TURN TOOL
            Case UFConstants.UF_CUTTER_TYPE_BARREL 'BARREL TOOL
                Dim toolBuilder As BarrelToolBuilder = workPart.CAMSetup.CAMGroupCollection.CreateBarrelToolBuilder(cBuilder)
    length = toolBuilder.TlHeightBuilder.Value
    shankLength = toolBuilder.T1TaperedShankLengthBuilder.Value
                'params("SphereDiameter") = toolBuilder.TlDiameterBuilder.Value
                'params("StemDiameter") = toolBuilder.TlShankDiaBuilder.Value
                'cutterLength = params("Length")
                'teeth = 1
    'shankLength = toolBuilder.T1TaperedShankLengthBuilder.Value
            Case UFConstants.UF_CUTTER_TYPE_T 'T CUTTER TOOL
            Case UFConstants.UF_CUTTER_TYPE_FORM
            Case UFConstants.UF_CUTTER_TYPE_GROOVE
            Case UFConstants.UF_CUTTER_TYPE_SOLID
            Case Else
        End Select
        GetCutterLength = length
    End Function
    Public Function GetVLength(ByVal vId As String)
        Dim tool As XmlNode
        Dim reader As XmlNodeReader
        Dim gaugeLength As Double = 0
  Dim lengthFound As Boolean = False
  
        For Each tool In tlsTools
            reader = New XmlNodeReader(tool)
            reader.MoveToContent()
            reader.MoveToFirstAttribute()
            Dim toolVId As String = Trim(reader.Value)
            If toolVId = Trim(vId) Then
                Dim gageNode As XmlNode = Nothing
                gageNode = tool.SelectSingleNode("GagePoint/Z")
                If Not gageNode Is Nothing Then
                    reader = New XmlNodeReader(gageNode)
                    reader.MoveToContent()
                    gaugeLength = reader.ReadElementContentAsDouble()
     lengthFound = True
                End If
            End If
        Next
        GetVLength = gaugeLength
    End Function
    Function BuildTlsFile()
        Dim masterTlsFile As New XmlDocument()
        Dim newTlsFile As New XmlDocument()
        Dim success As Boolean = False
        If toolList.Count = 0 Then
            msgBox("No Tools identified.")
            Return success
        End If
        'Check source Files Exist
        If Not File.Exists(refTlsFilePath) Then
            msgBox("TLS File Not Found!")
            Exit Function
        End If
        If Not File.Exists(masterTlsFilePath) Then
            msgBox("Master TLS File Not Found!")
            Exit Function
        End If
        If File.Exists(newTlsFilePath) Then
            File.Delete(newTlsFilePath)
        End If
       
        File.Copy(refTlsFilePath, newTlsFilePath, True)
        'Load Master TLS XML File
        masterTlsFile.Load(masterTlsFilePath)
        Dim root As XmlElement = masterTlsFile.DocumentElement
        Dim tlsTools As XmlNodeList = root.SelectNodes("/CGTechToolLibrary/Tools/Tool")
        If tlsTools.Count <= 0 Then
            msgBox("Unable to open Vericut Tool File")
            Exit Function
        End If
        'Load New TLS XML File
        newTlsFile.Load(newTlsFilePath)
        Dim toolNode As XmlNode = newTlsFile.DocumentElement.SelectSingleNode("/CGTechToolLibrary/Tools")
        'Cycle through master tools and copy required tools to new TLS File
        ' and retrieve holders and Tools 27,29,30,39,40
        For Each tool As XmlNode In tlsTools
            Dim toolId As String = tool.Attributes("ID").Value
            If toolList.Contains(toolId) Then
                'Copy Tool to each toolid
                Dim toolArr() As String = Split(toolList(toolId), ",")
                For Each toolNo As String In toolArr
                    tool.Attributes("ID").Value = toolNo
                    toolNode.AppendChild(newTlsFile.ImportNode(tool, True))
                Next
                toolList.Remove(toolId)
            Else
                If tool.Attributes("ID").Value = "27" Or tool.Attributes("ID").Value = "29" Or tool.Attributes("ID").Value = "30" Or tool.Attributes("ID").Value = "39" Or tool.Attributes("ID").Value = "40" Then
                    'Check if its T27, 29 or 30
                    toolNode.AppendChild(newTlsFile.ImportNode(tool, True))
                Else
                    'Check if its a holder
                    Dim cutterElem As XmlElement = tool.Item("Cutter")
                    If cutterElem Is Nothing Then
                        'msgBox("HOLDER")
                        toolNode.AppendChild(newTlsFile.ImportNode(tool, True))
                    End If
                End If
            End If
        Next
        newTlsFile.Save(newTlsFilePath)
        'Check all tools have been found
        If toolList.Count > 0 Then
            Dim errorStr = "The following tools Couldn't be found in Vericut:" & VbCrLf & VbCrLf
            For Each tool As DictionaryEntry In toolList
                errorStr &= "Tool Number " & tool.Value & " (ATMS ID: " & tool.Key & ")" & VbCrLf
            Next
            msgBox(errorStr)
        Else
            success = True
        End If
        Return success
    End Function
End Module

 

Any assistance is greatly received.

 

 

Regards

Dave
NX10.0.3MP13
NX11.0.1
Production
TC10
Vericut 7.3,7.4.1,8.0.2
1 REPLY

Re: Get the value of GetTaperedShankLength(millToolBuilder)

Dave,

I reformatted your post using "code" tags to make it easier to read.

 

I think we need some more information to offer any help:

  • Is this a journal you can just run from NX?
  • What exactly is the error - message? Line number?
  • What did you change already?

Who wrote the original script? If it is part of CGTech's NX interface, they should have an update.

Mark Rief
Retired Siemens