Cancel
Showing results for 
Search instead for 
Did you mean: 

Cut direction flipping Journal for selected toolpaths

Experimenter
Experimenter

Hi All,

With Help of Mark and Stefan. I have  modified journal which suits for cut direction change from climb to conventional or vice versa for all mill type operations. This journal will useful for who are all working for shown and opposite parts

 

here is the code

 

'=============================================================================
'
'   Copyright 2015 Siemens Product Lifecycle Management Software Inc. All Rights Reserved.
'
'=============================================================================
'  REVISIONS

'     05-mar-2015  Mark Rief  adapt for cut direction 
' 	24-mar-2015  Ganesh Kothakota modified for all mill operations cut direction change vice versa
'
' ===========================================================================
'   DESCRIPTION

'     This program will edit selected ALL mill TYPE operations CUT DIRECTION vice versa
'	This Program will change cut direction without regenerate except Volumill. 
‘	Only Volumill operation will regenerate before and after cut direction change
'	
'     This can be used as a boiler plate to set other method parameters.
' ============================================================================
 
Option Strict Off
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.CAM
Imports NXOpen.UF
Imports NXOpen.Utilities

Module Cutdirection_change

    Dim theSession As Session
    Dim theUfSession As UFSession


    Sub Main()

        theSession = Session.GetSession()
        theUfSession = UFSession.GetUFSession()
		
        Dim WorkPart As Part = TheSession.Parts.Work

        Dim setupTag As Tag
        Dim camObjectTag As Tag
        Dim selectedTags() As NXOpen.Tag
        Dim selectedCount As Integer

        theUfSession.Cam.InitSession()
        theUfSession.Setup.AskSetup(setupTag)

        ' If there is a setup only then we go further
        If setupTag <> 0 Then

            ' Get the selected nodes from the Operation Navigator
            theUfSession.UiOnt.AskSelectedNodes(selectedCount, selectedTags)

            Dim ptr As IntPtr = New System.IntPtr
            Dim cycle_cb_fn As UFNcgroup.CycleCbFT = New UFNcgroup.CycleCbFT(AddressOf cycle_cb)

            Dim i As Integer
            'Loop over the selected nodes to take action
            For i = 0 To selectedCount - 1
                ' The selected item needs to be checked to take action
                action(selectedTags(i))
                ' Now if the selected item is a Group object then we need to cycle objects inside it
                theUfSession.Ncgroup.CycleMembers(selectedTags(i), cycle_cb_fn, ptr)
            Next i
        End If

    End Sub


    Function cycle_cb(ByVal camObjectTag As Tag, ByVal ptr As IntPtr) As Boolean

        Dim answer As Boolean
        ' Every item needs to be checked to take action
        answer = action(camObjectTag)
        Return answer

    End Function

    Function action(ByVal camObjectTag As Tag) As Boolean

        Dim camObject As NXObject = NXObjectManager.Get(camObjectTag)
        Dim WorkPart As Part = TheSession.Parts.Work
		
        'Check if the object is an Operation
        If TypeOf camObject Is CAM.Operation Then
            Dim operationType As Integer
            Dim operationSubtype As Integer

            'Get the type and subtype of the operation
            theUFSession.Obj.AskTypeAndSubtype(camObjectTag, operationType, operationSubtype)
				theSession.ListingWindow.Open()
				theSession.ListingWindow.WriteLine("operationSubtype = " & operationSubtype)


If operationSubtype = 800 Then
'This  WILL Regenerate volmill path to get attributes
			Dim oOpers(0) As Cam.Operation
			oOpers(0) = camObject
			WorkPart.CAMSetup.GenerateToolPath(oOpers)
  		' Set cut direction
				'camObject.SetAttribute("VM_cutDirection", "0")  ' THIS SETS VOLMILL TO CLIMB
				camObject.SetAttribute("VM_cutDirection", "1")  ' THIS SETS VOLMILL TO CONVENTIONAL
		' Comment the following two lines to suppress the listing window
				theSession.ListingWindow.Open()
				theSession.ListingWindow.WriteLine("Parameters set in: " & camObject.Name() )
		'This  WILL Regenerate volmill path to APPLY attributes
			Dim oOpers1(0) As Cam.Operation
			oOpers1(0) = camObject
			WorkPart.CAMSetup.GenerateToolPath(oOpers1)
Else
          
	'Change cut direction CLOCKWISE to counter-clockwise OR VICE VERSA
	'0 ... undefined (what to use in this case ???)
	'1 ... clockwise
	'2 ... counter-clockwise
	'3 ... forward
	'4 ... reverse
	'5 ... mixed

	Dim CurrentDirection As Integer
	Const REGION_CUT_DIRECTION_TYPE As Integer = 305

		Try
   		 theUfSession.Param.AskIntValue(camObjectTag, UFConstants.UF_PARAM_CUT_DIR_TYPE, CurrentDirection)
    
    		If CurrentDirection = 1 or CurrentDirection = 2 Then
        		theUfSession.Param.SetIntValue(camObjectTag, UFConstants.UF_PARAM_CUT_DIR_TYPE, ChangeCutDirection(CurrentDirection))
   		 Else
        		theUfSession.Param.AskIntValue(camObjectTag, REGION_CUT_DIRECTION_TYPE, CurrentDirection)
        
       		 If CurrentDirection = 1 or CurrentDirection = 2 Then
            	theUfSession.Param.SetIntValue(camObjectTag, REGION_CUT_DIRECTION_TYPE, ChangeCutDirection(CurrentDirection))
        End If
    End If

Catch e As Exception
    theSession.LogFile.WriteLine(e.Message)
End Try    	
              

				' Comment the following two lines to suppress the listing window
				theSession.ListingWindow.Open()
				theSession.ListingWindow.WriteLine("Parameters set in: " & camObject.Name() )
				  			
	End If
End If		
				
        Return True
    End Function
Private Function CheckCutDirection(CutDir As Integer) As String
    Select Case CutDir
        Case 0
            Return "Undefined"
        Case 1
            Return "Clockwise"
        Case 2
            Return "Counter-Clockwise"
        Case 3
            Return "Forward"
        Case 4
            Return "Reverse"
        Case 5
            Return "Mixed"
        Case Else
            Return "N/A"
    End Select
End Function

Private Function ChangeCutDirection(CutDir As Integer) As Integer
    Select Case CutDir
        Case 1
            Return 2
        Case 2
            Return 1
        Case 3
            Return 4
        Case 4
            Return 3
        Case Else
            Return 0
    End Select
End Function
End Module

 

 

Regards,

Ganesh kothakota

CAD/CAM LEAD

Techmahindra Inc. 

GANESH KOTHAKOTA
CAD/CAM LEAD
TECHMAHINDRA INC.

Learn online





Solution Information