set attributes in journal vice versa

Hi All,
I am trying to modify journal for change of cut direction and to get this I need to change my attribute called "VM_cutDirection" in my cam object. In my journal I can able to change through set attributes but I would like to automate little for this.
If my attribute is 0 then needs to set as 1 or vice versa. I am unable make if statement for that Can anyone help me in this here is my code.
Option Strict Off
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.CAM
Imports NXOpen.UF
Imports NXOpen.Utilities

Module ChangeCutDirection

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)
End If

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() )
Dim oOpers1(0) As Cam.Operation
oOpers1(0) = camObject
WorkPart.CAMSetup.GenerateToolPath(oOpers1)

End Function

End Module

If the attribute value is only going to take on one of two values, the easiest would be to use a boolean attribute type. You could simply set the value to Not(currentValue).

The example code below shows how to do this. It also shows how to toggle a string attribute between the values of "0" and "1" (as per your supplied code).

Before running the code, create a boolean attribute with the name "toggle". Also, create a string attribute with the name "toggle2" and a value of "0" or "1".

Option Strict Off
Imports System
Imports NXOpen

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "toggle boolean attribute"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Const attributeName As String = "toggle"

'Toggle the value of the boolean attribute
If workPart.HasUserAttribute(attributeName, NXObject.AttributeType.Boolean, -1) Then
MsgBox("current value of " & attributeName & ": " & workPart.GetBooleanUserAttribute(attributeName, -1).ToString)
workPart.SetBooleanUserAttribute(attributeName, -1, Not (workPart.GetBooleanUserAttribute(attributeName, -1)), Update.Option.Now)
MsgBox("new value of " & attributeName & ": " & workPart.GetBooleanUserAttribute(attributeName, -1).ToString)
Else
MsgBox("attribute: '" & attributeName & "' not found")
End If

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Const attributeName2 As String = "toggle2"
Dim value2 As String = ""
'Toggle the value of the string attribute
If workPart.HasUserAttribute(attributeName2, NXObject.AttributeType.String, -1) Then
value2 = workPart.GetStringUserAttribute(attributeName2, -1)
MsgBox("current value of " & attributeName2 & ": " & value2)
If value2 = "0" Then
value2 = "1"
Else
value2 = "0"
End If
workPart.SetUserAttribute(attributeName2, -1, value2, Update.Option.Now)
value2 = workPart.GetStringUserAttribute(attributeName2, -1)
MsgBox("new value of " & attributeName2 & ": " & value2)

Else
MsgBox("attribute: '" & attributeName2 & "' not found")
End If

lw.Close()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Hi,
I tried both ways to implementing your code in my journal but it's not detecting my cam object attribute. My cam object attribute name is "VM_cutDirection" here I am attaching my modified code

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

Module ChangeCutDirection

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)
End If

Dim oOpers(0) As Cam.Operation
oOpers(0) = camObject
WorkPart.CAMSetup.GenerateToolPath(oOpers)

Const undoMarkName As String = "VM_cutDirection boolean attribute"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Const attributeName2 As String = "VM_cutDirection"
Dim value2 As String = ""
'Toggle the value of the string attribute
If workPart.HasUserAttribute(attributeName2, NXObject.AttributeType.String, -1) Then
value2 = workPart.GetStringUserAttribute(attributeName2, -1)
MsgBox("current value of " & attributeName2 & ": " & value2)
If value2 = "0" Then
value2 = "1"
Else
value2 = "0"
End If
workPart.SetUserAttribute(attributeName2, -1, value2, Update.Option.Now)
value2 = workPart.GetStringUserAttribute(attributeName2, -1)
MsgBox("new value of " & attributeName2 & ": " & value2)

Else
MsgBox("attribute: '" & attributeName2 & "' not found")
End If

' 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() )
Dim oOpers1(0) As Cam.Operation
oOpers1(0) = camObject
WorkPart.CAMSetup.GenerateToolPath(oOpers1)

End Function

End Module

and here is my Boolean code

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

Module ChangeCutDirection

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)
End If

Dim oOpers(0) As Cam.Operation
oOpers(0) = camObject
WorkPart.CAMSetup.GenerateToolPath(oOpers)

Const undoMarkName As String = "VM_cutDirection boolean attribute"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Const attributeName As String = "VM_cutDirection"

'Toggle the value of the boolean attribute
If camObject.HasUserAttribute(attributeName, NXObject.AttributeType.Boolean, -1) Then
MsgBox("current value of " & attributeName & ": " & camObject.GetBooleanUserAttribute(attributeName, -1).ToString)
camObject.SetBooleanUserAttribute(attributeName, -1, Not (camObject.GetBooleanUserAttribute(attributeName, -1)), Update.Option.Now)
MsgBox("new value of " & attributeName & ": " & workPart.GetBooleanUserAttribute(attributeName, -1).ToString)
Else
MsgBox("attribute: '" & attributeName & "' not found")
End If

' 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() )
Dim oOpers1(0) As Cam.Operation
oOpers1(0) = camObject
WorkPart.CAMSetup.GenerateToolPath(oOpers1)

End Function

End Module

Best Regards,
Gani

You might want to check/update the camObject attributes as in your original code. I used the workPart's attributes for illustration because I don't have a file with CAM objects in it for testing. Use the same strategy as above on the camObject's attributes instead of the part attributes.

If you see my Boolean code I used cam object instead of work part but still attribute not updating.
How I can attach sample part file here

Best Regards,
Gani

Do you get a message that the attribute is not found or some other error message? Or does the code run, but the attribute is just not updated? Are you sure the cam object has a boolean type attribute with the name "VM_cutDirection"?

You are welcome to email me a part file (info@nxjournaling.com); however, I do not currently have access to a CAM license, so I'm not sure it will help...

I sent an snap shot email to info@nxjournaling.com

Best Regards,
Gani