NX How to create a script to disable contact data output in all operations

2021-10-06T23:27:35Z
NX for Manufacturing

Summary


Details

The site is changing cam programming processes and requires a Visual Basic journal that will cycle through all the operations in the current manufacturing setup and turn off the "output contact/tracking data" option on the More tab of noncutting moves.

Solution

The following script will cycle through all the operations, determining what kind they are, and apply this change to the noncutting moves if applicable.




' NX 12.0.2.9
'
Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.CAM
Imports NXOpen.UF
Imports NXOpen.Utilities

Module OutputTracking

    Dim theSession As Session
    Dim theUfSession As UFSession

    Sub Main()
        theSession = Session.GetSession()
        theUfSession = UFSession.GetUFSession()
        Dim WorkPart As Part = TheSession.Parts.Work
        ' If there is a work part only then we can go further
        If WorkPart IsNot Nothing Then
 Try
 If WorkPart.CAMSetup() IsNot Nothing Then
 'If Cam Session is not initialized then we have to create a session
 If theSession.IsCamSessionInitialized() = False Then
 theSession.CreateCamSession()
 End If
 ActOnOperations(WorkPart, WorkPart.CAMSetup())
 End If
 Catch ex As Exception
 WriteLine(ex.Message)
 End Try 
        End If
    End Sub

 Sub ActOnOperations(ByVal thePart As Part, ByVal setup As CAM.CAMSetup) 
 Dim operationType As String
 Dim operationBuilder As CAM.OperationBuilder
 For Each operation As NXOpen.CAM.Operation In  setup.CAMOperationCollection()
     ' Get the operation type
 operationType = GetOperationType(operation)
 If operationType IsNot Nothing Then
 ' create the proper operation builder
 operationBuilder = GetOperationBuilder(thePart,operation,operationType)
 If operationBuilder IsNot Nothing Then
 'Set the output tracking flag to off
 SetCutcomOutput(operationBuilder)
 'Commit the change to the operation( this is the equivalent of OK'ing the operation dialog )
 operationBuilder.Commit()
 'Destroy the builder when its job is done(cleanup memory)
 operationBuilder.Destroy()
 End If
 End If
 Next
 End Sub
 
 Sub SetCutcomOutput(ByVal operationBuilder As CAM.OperationBuilder)
 ' Only handle Planar operations and Holemachining Operations.
 If TypeOf operationBuilder Is CAM.PlanarOperationBuilder Then 
 Dim planarOperationBuilder As CAM.PlanarOperationBuilder = CType(operationBuilder, CAM.PlanarOperationBuilder)
 planarOperationBuilder.NonCuttingBuilder.CutcomOutputContactPoint = False
 Else If TypeOf operationBuilder Is CAM.HoleMachiningBuilder Then
 Dim holeMachiningBuilder As CAM.HoleMachiningBuilder = CType(operationBuilder, CAM.HoleMachiningBuilder)
 holeMachiningBuilder.NonCuttingBuilder.CutcomOutputContactPoint = False
 End If
 End Sub
 
 'Function to get the operation type
    Function GetOperationType(ByVal camObject As CAM.Operation) As String
 Dim operationType As String = Nothing

 If TypeOf camObject Is CAM.Engraving Then              ' This is a Planar Engraving Operation
 operationType = "Engraving"
        ElseIf TypeOf camObject Is CAM.PlanarMilling Then           ' This is a Planar Milling Operation
 operationType = "Planar Milling"
        ElseIf TypeOf camObject Is CAM.CavityMilling Then          ' This is a Cavity Milling Operation
 operationType = "Cavity Milling"
        ElseIf TypeOf camObject Is CAM.FaceMilling Then          ' This is a Face Milling Operation
 operationType = "Face Milling"
        ElseIf TypeOf camObject Is CAM.ZLevelMilling Then          ' This is a Z Level Milling Operation
 operationType = "Z Level Milling"
        ElseIf TypeOf camObject Is CAM.VariableZLevelMilling Then   ' This is a Variable Axis Z Level Milling Operation
 operationType = "Variable Z Level Milling"
 ElseIf TypeOf camObject Is CAM.PlungeMilling Then          ' This is a Plunge Milling Operation 
 operationType = "Plunge Milling"
 ElseIf TypeOf camObject Is CAM.FeatureMilling Then          ' This is a Feature Milling Operation
 operationType = "Feature Milling"
        ElseIf TypeOf camObject Is CAM.SurfaceContour Then          ' This is a Fixed Axis Surface Contour Operation 
 operationType = "Surface Contour"
 ElseIf TypeOf camObject Is CAM.HoleDrilling ' This is a Hole Drilling Operation 
 operationType = "Hole Drilling"
 ElseIf TypeOf camObject Is CAM.ThreadMilling ' This is a Thread Milling Operation 
 operationType = "Thread Milling"
 ElseIf TypeOf camObject Is CAM.HoleMaking ' This is a Hole Making Operation 
 operationType = "Hole Making"
 ElseIf TypeOf camObject Is CAM.CylinderMilling ' This is a Cylinder Milling Operation 
 operationType = "Cylinder Milling"
 ElseIf TypeOf camObject Is CAM.ChamferMilling ' This is a Chamfer Milling Operation 
 operationType = "Chamfer Milling"
 ElseIf TypeOf camObject Is CAM.MillMachineControl ' This is a Mill Machine Control Operation 
 operationType = "Mill Machine Control"
 ElseIf TypeOf camObject Is CAM.LatheMachineControl ' This is a Lathe Machine Control Operation 
 operationType = "Lathe machine Control"
 ElseIf TypeOf camObject Is CAM.MillUserDefined ' This is a Mill User Defined Operation 
 operationType = "Mill User Defined"
 ElseIf TypeOf camObject Is CAM.LatheUserDefined ' This is a Lathe User Defined Operation 
 operationType = "lathe User Defined"
 ElseIf TypeOf camObject Is CAM.FinishTurning    ' This is a Finish Turning Operation 
 operationType = "Turn Finishing"
 ElseIf TypeOf camObject Is CAM.RoughTurning       ' This is a Rough Turning Operation 
 operationType = "Turn Roughing"
 ElseIf TypeOf camObject Is CAM.CenterlineDrillTurning     ' This is a Centerline Drill Turning Operation 
 operationType = "Turn Centerline Drilling"
 ElseIf TypeOf camObject Is CAM.ThreadTurning ' This is a Thread Turning Operation
 operationType = "Turn Threading"
 Else
     Dim operType As Integer
            Dim operationSubtype As Integer
            'Get the type and subtype of the operation
            theUfSession.Obj.AskTypeAndSubtype(camObject.Tag, operType, operationSubtype)
 If operationSubtype = 900 'Generic Motion Operation
 operationType = "GMC"
 ElseIf operationSubtype = 530 'Turn Teach Operation
 operationType = "Turn Teach Mode"
 End If
        End If
        Return operationType
    End Function
 
 'Function to get the operation builder
    Function GetOperationBuilder(ByVal workPart As Part, ByVal camObject As CAM.Operation, ByVal operationType As String) As CAM.ParamBuilder
        Dim operationBuilder As CAM.ParamBuilder = Nothing

 If operationType = "Engraving"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateEngravingBuilder(camObject)
        ElseIf operationType = "Planar Milling" 
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreatePlanarMillingBuilder(camObject)
        ElseIf operationType = "Cavity Milling"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateCavityMillingBuilder(camObject)
        ElseIf operationType = "Face Milling"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateFaceMillingBuilder(camObject)
        ElseIf operationType = "Z Level Milling"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateZlevelMillingBuilder(camObject)
        ElseIf operationType = "Variable Z Level Milling"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateVazlMillingBuilder(camObject)
 ElseIf operationType = "Plunge Milling"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreatePlungeMillingBuilder(camObject)
 ElseIf operationType = "Feature Milling"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateFeatureMillingBuilder(camObject)
        ElseIf operationType = "Surface Contour"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateSurfaceContourBuilder(camObject)
 ElseIf operationType = "Hole Drilling"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateHoleDrillingBuilder(camObject)
 ElseIf operationType = "Thread Milling"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateThreadMillingBuilder(camObject)
 ElseIf operationType = "Hole Making" 
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateHoleMakingBuilder(camObject)
 ElseIf operationType = "Cylinder Milling"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateCylinderMillingBuilder(camObject)
 ElseIf operationType = "Chamfer Milling"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateChamferMillingBuilder(camObject)
 ElseIf operationType = "Mill Machine Control" 
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateMillMachineControlBuilder(camObject)
 ElseIf operationType = "Lathe machine Control"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateLatheMachineControlBuilder(camObject)
 ElseIf operationType = "Mill User Defined"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateMillUserDefinedBuilder(camObject)
 ElseIf operationType = "lathe User Defined"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateLatheUserDefinedBuilder(camObject)
 ElseIf operationType = "Turn Finishing"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateFinishTurningBuilder(camObject)
 ElseIf operationType = "Turn Roughing"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateRoughTurningBuilder(camObject)
 ElseIf operationType = "Turn Centerline Drilling"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateCenterlineDrillTurningBuilder(camObject)
 ElseIf operationType = "Turn Threading"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateThreadTurningBuilder(camObject)
 ElseIf operationType = "GMC"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateGmcopBuilder(camObject)
 ElseIf operationType = "Turn Teach Mode"
 operationBuilder = workPart.CAMSetup.CAMOperationCollection.CreateTeachmodeTurningBuilder(camObject)
        End If
        Return operationBuilder
    End Function
End Module



Hardware/Software Configuration

Platform: all
OS: n/a
OS Version: n/a
Product: NX
Application: CAM
Version: V12.0.2
Function: JOURNALING

Ref: 002-8016844

KB Article ID# PL8016844

Contents

SummaryDetails

Associated Components

Manufacturing General