Journal- for creating a mill path generation profile

Hi,

Currently I am trying to create a journal for slicing a body and creating a mill path generation on the slice using the boundaries of the face. The journal performs all the operations aacept selecting the face geometry and hence the milling path is not generated. The Journal code is as follows.
Could anyone help me with the same ?

Thanks

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

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

Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: Insert->Operation...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create Operation")

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

Dim method1 As CAM.Method = CType(workPart.CAMSetup.CAMGroupCollection.FindObject("METHOD"), CAM.Method)

Dim tool1 As CAM.Tool = CType(workPart.CAMSetup.CAMGroupCollection.FindObject("MILL"), CAM.Tool)

Dim orientGeometry1 As CAM.OrientGeometry = CType(workPart.CAMSetup.CAMGroupCollection.FindObject("MCS"), CAM.OrientGeometry)

Dim operation1 As CAM.Operation
operation1 = workPart.CAMSetup.CAMOperationCollection.Create(nCGroup1, method1, tool1, orientGeometry1, "mill_planar", "FACE_MILLING", CAM.OperationCollection.UseDefaultName.True, "FACE_MILLING")

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")

Dim faceMilling1 As CAM.FaceMilling = CType(operation1, CAM.FaceMilling)

Dim faceMillingBuilder1 As CAM.FaceMillingBuilder
faceMillingBuilder1 = workPart.CAMSetup.CAMOperationCollection.CreateFaceMillingBuilder(faceMilling1)

theSession.SetUndoMarkName(markId2, "Face Milling Dialog")

' ----------------------------------------------
' Dialog Begin Face Milling
' ----------------------------------------------
Dim nXObject1 As NXObject
nXObject1 = faceMillingBuilder1.Commit()

Dim objectsToBeMoved1(0) As CAM.CAMObject
Dim faceMilling2 As CAM.FaceMilling = CType(nXObject1, CAM.FaceMilling)

objectsToBeMoved1(0) = faceMilling2
Dim featureGeometry1 As CAM.FeatureGeometry = CType(workPart.CAMSetup.CAMGroupCollection.FindObject("WORKPIECE"), CAM.FeatureGeometry)

workPart.CAMSetup.MoveObjects(CAM.CAMSetup.View.Geometry, objectsToBeMoved1, featureGeometry1, CAM.CAMSetup.Paste.Inside)

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Face Milling")

theSession.DeleteUndoMark(markId3, Nothing)

Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Face Milling")

theSession.DeleteUndoMark(markId4, Nothing)

theSession.SetUndoMarkName(markId2, "Face Milling")

faceMillingBuilder1.Destroy()

theSession.DeleteUndoMark(markId2, Nothing)

Dim markId5 As Session.UndoMarkId
markId5 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")

Dim faceMillingBuilder2 As CAM.FaceMillingBuilder
faceMillingBuilder2 = workPart.CAMSetup.CAMOperationCollection.CreateFaceMillingBuilder(faceMilling2)

theSession.SetUndoMarkName(markId5, "Face Milling Dialog")

' ----------------------------------------------
' Dialog Begin Face Milling
' ----------------------------------------------
Dim nXObject2 As NXObject
nXObject2 = faceMillingBuilder2.Commit()

Dim markId6 As Session.UndoMarkId
markId6 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")

Dim millGeomBuilder1 As CAM.MillGeomBuilder
millGeomBuilder1 = workPart.CAMSetup.CAMGroupCollection.CreateMillGeomBuilder(featureGeometry1)

Dim geometryCiBuilder1 As CAM.GeometryCiBuilder
geometryCiBuilder1 = millGeomBuilder1.GeometryCiBuilder

theSession.SetUndoMarkName(markId6, "Workpiece Dialog")

' ----------------------------------------------
' Dialog Begin Workpiece
' ----------------------------------------------
millGeomBuilder1.PartGeometry.InitializeData(False)

Dim markId7 As Session.UndoMarkId
markId7 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")

theSession.SetUndoMarkName(markId7, "Part Geometry Dialog")

Dim taggedObject1 As TaggedObject
taggedObject1 = millGeomBuilder1.PartGeometry.GeometryList.FindItem(0)

Dim geometrySet1 As CAM.GeometrySet = CType(taggedObject1, CAM.GeometrySet)

' ----------------------------------------------
' Dialog Begin Part Geometry
' ----------------------------------------------
Dim markId8 As Session.UndoMarkId
markId8 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Part Geometry")

theSession.DeleteUndoMark(markId8, Nothing)

Dim markId9 As Session.UndoMarkId
markId9 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Part Geometry")

theSession.DeleteUndoMark(markId9, Nothing)

theSession.SetUndoMarkName(markId7, "Part Geometry")

theSession.DeleteUndoMark(markId7, Nothing)

Dim markId10 As Session.UndoMarkId
markId10 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Workpiece")

theSession.DeleteUndoMark(markId10, Nothing)

Dim markId11 As Session.UndoMarkId
markId11 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Workpiece")

Dim nXObject3 As NXObject
nXObject3 = millGeomBuilder1.Commit()

theSession.DeleteUndoMark(markId11, Nothing)

theSession.SetUndoMarkName(markId6, "Workpiece")

millGeomBuilder1.Destroy()

theSession.DeleteUndoMark(markId6, Nothing)

Dim markId12 As Session.UndoMarkId
markId12 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")

Dim featureGeometry2 As CAM.FeatureGeometry = CType(nXObject3, CAM.FeatureGeometry)

Dim millGeomBuilder2 As CAM.MillGeomBuilder
millGeomBuilder2 = workPart.CAMSetup.CAMGroupCollection.CreateMillGeomBuilder(featureGeometry2)

Dim geometryCiBuilder2 As CAM.GeometryCiBuilder
geometryCiBuilder2 = millGeomBuilder2.GeometryCiBuilder

theSession.SetUndoMarkName(markId12, "Workpiece Dialog")

' ----------------------------------------------
' Dialog Begin Workpiece
' ----------------------------------------------
millGeomBuilder2.BlankGeometry.InitializeData(False)

Dim markId13 As Session.UndoMarkId
markId13 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")

theSession.SetUndoMarkName(markId13, "Blank Geometry Dialog")

Dim taggedObject2 As TaggedObject
taggedObject2 = millGeomBuilder2.BlankGeometry.GeometryList.FindItem(0)

Dim geometrySet2 As CAM.GeometrySet = CType(taggedObject2, CAM.GeometrySet)

' ----------------------------------------------
' Dialog Begin Blank Geometry
' ----------------------------------------------
Dim markId14 As Session.UndoMarkId
markId14 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Blank Geometry")

theSession.DeleteUndoMark(markId14, Nothing)

Dim markId15 As Session.UndoMarkId
markId15 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Blank Geometry")

theSession.DeleteUndoMark(markId15, Nothing)

theSession.SetUndoMarkName(markId13, "Blank Geometry")

theSession.DeleteUndoMark(markId13, Nothing)

Dim markId16 As Session.UndoMarkId
markId16 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Workpiece")

theSession.DeleteUndoMark(markId16, Nothing)

Dim markId17 As Session.UndoMarkId
markId17 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Workpiece")

Dim nXObject4 As NXObject
nXObject4 = millGeomBuilder2.Commit()

theSession.DeleteUndoMark(markId17, Nothing)

theSession.SetUndoMarkName(markId12, "Workpiece")

millGeomBuilder2.Destroy()

theSession.DeleteUndoMark(markId12, Nothing)

Dim markId18 As Session.UndoMarkId
markId18 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")

Dim featureGeometry3 As CAM.FeatureGeometry = CType(nXObject4, CAM.FeatureGeometry)

Dim millGeomBuilder3 As CAM.MillGeomBuilder
millGeomBuilder3 = workPart.CAMSetup.CAMGroupCollection.CreateMillGeomBuilder(featureGeometry3)

Dim geometryCiBuilder3 As CAM.GeometryCiBuilder
geometryCiBuilder3 = millGeomBuilder3.GeometryCiBuilder

theSession.SetUndoMarkName(markId18, "Workpiece Dialog")

' ----------------------------------------------
' Dialog Begin Workpiece
' ----------------------------------------------
Dim markId19 As Session.UndoMarkId
markId19 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Workpiece")

theSession.DeleteUndoMark(markId19, Nothing)

Dim markId20 As Session.UndoMarkId
markId20 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Workpiece")

Dim nXObject5 As NXObject
nXObject5 = millGeomBuilder3.Commit()

theSession.DeleteUndoMark(markId20, Nothing)

theSession.SetUndoMarkName(markId18, "Workpiece")

millGeomBuilder3.Destroy()

theSession.DeleteUndoMark(markId18, Nothing)

Dim markId21 As Session.UndoMarkId
markId21 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Face Milling")

theSession.DeleteUndoMark(markId21, Nothing)

Dim markId22 As Session.UndoMarkId
markId22 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Face Milling")

theSession.DeleteUndoMark(markId22, Nothing)

theSession.SetUndoMarkName(markId5, "Face Milling")

faceMillingBuilder2.Destroy()

theSession.DeleteUndoMark(markId5, Nothing)

Dim markId23 As Session.UndoMarkId
markId23 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")

Dim faceMilling3 As CAM.FaceMilling = CType(nXObject2, CAM.FaceMilling)

Dim faceMillingBuilder3 As CAM.FaceMillingBuilder
faceMillingBuilder3 = workPart.CAMSetup.CAMOperationCollection.CreateFaceMillingBuilder(faceMilling3)

theSession.SetUndoMarkName(markId23, "Face Milling Dialog")

' ----------------------------------------------
' Dialog Begin Face Milling
' ----------------------------------------------
' ----------------------------------------------
' Dialog Begin Specify Face Geometry
' ----------------------------------------------
Dim markId24 As Session.UndoMarkId
markId24 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Face Milling")

theSession.DeleteUndoMark(markId24, Nothing)

Dim markId25 As Session.UndoMarkId
markId25 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Face Milling")

Dim nXObject6 As NXObject
nXObject6 = faceMillingBuilder3.Commit()

theSession.DeleteUndoMark(markId25, Nothing)

theSession.SetUndoMarkName(markId23, "Face Milling")

faceMillingBuilder3.Destroy()

theSession.DeleteUndoMark(markId23, Nothing)

Dim markId26 As Session.UndoMarkId
markId26 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")

Dim faceMilling4 As CAM.FaceMilling = CType(nXObject6, CAM.FaceMilling)

Dim faceMillingBuilder4 As CAM.FaceMillingBuilder
faceMillingBuilder4 = workPart.CAMSetup.CAMOperationCollection.CreateFaceMillingBuilder(faceMilling4)

theSession.SetUndoMarkName(markId26, "Face Milling Dialog")

' ----------------------------------------------
' Dialog Begin Face Milling
' ----------------------------------------------
faceMillingBuilder4.ToolAxisFix.ToolAxisType = CAM.ToolAxisFixed.Types.Fixed

Dim markId27 As Session.UndoMarkId
markId27 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")

Dim unit1 As Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), Unit)

Dim expression1 As Expression
expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression2 As Expression
expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

theSession.SetUndoMarkName(markId27, "Vector Dialog")

' ----------------------------------------------
' Dialog Begin Vector
' ----------------------------------------------
Dim splitBody1 As Features.SplitBody = CType(workPart.Features.FindObject("SPLIT BODY(320)"), Features.SplitBody)

Dim face1 As Face = CType(splitBody1.FindObject("FACE 1 {(2.5,29.2103140834147,275.2686953680443) SPLIT BODY(320)1}"), Face)

Dim direction1 As Direction
direction1 = workPart.Directions.CreateDirection(face1, Sense.Forward, SmartObject.UpdateOption.AfterModeling)

Dim markId28 As Session.UndoMarkId
markId28 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Vector")

theSession.DeleteUndoMark(markId28, Nothing)

Dim markId29 As Session.UndoMarkId
markId29 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Vector")

theSession.DeleteUndoMark(markId29, Nothing)

theSession.SetUndoMarkName(markId27, "Vector")

workPart.Expressions.Delete(expression1)

workPart.Expressions.Delete(expression2)

theSession.DeleteUndoMark(markId27, Nothing)

faceMillingBuilder4.ToolAxisFix.Vector = direction1

faceMillingBuilder4.CutPattern.CutPattern = CAM.CutPatternBuilder.Types.ZigZag

Dim markId30 As Session.UndoMarkId
markId30 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")

Dim origin1 As Point3d = New Point3d(0.0, 0.0, 0.0)
Dim normal1 As Vector3d = New Vector3d(0.0, 0.0, 1.0)
Dim plane1 As Plane
plane1 = workPart.Planes.CreatePlane(origin1, normal1, SmartObject.UpdateOption.AfterModeling)

Dim expression3 As Expression
expression3 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression4 As Expression
expression4 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression5 As Expression
expression5 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

Dim expression6 As Expression
expression6 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

theSession.SetUndoMarkName(markId30, "Cutting Parameters Dialog")

' ----------------------------------------------
' Dialog Begin Cutting Parameters
' ----------------------------------------------
faceMillingBuilder4.CutParameters.CutAngle.Type = CAM.CutAngle.Types.Vector

Dim thicken1 As Features.Thicken = CType(workPart.Features.FindObject("THICKEN_SHEET(23)"), Features.Thicken)

Dim edge1 As Edge = CType(thicken1.FindObject("EDGE * [solid(1) FACE 300074] SPLIT BODY(320) 1 {(-13,-16.6311911813027,279.6642526112706)(2.5,-7.6517802837373,278.8032530785812)(18,1.3276306138282,277.9422535458918) SPLIT BODY(320)1}"), Edge)

Dim direction2 As Direction
direction2 = workPart.Directions.CreateDirection(edge1, Sense.Reverse, SmartObject.UpdateOption.AfterModeling)

faceMillingBuilder4.CutParameters.CutAngle.Vector = direction2

Dim markId31 As Session.UndoMarkId
markId31 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Cutting Parameters")

theSession.DeleteUndoMark(markId31, Nothing)

Dim markId32 As Session.UndoMarkId
markId32 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Cutting Parameters")

theSession.DeleteUndoMark(markId32, Nothing)

theSession.SetUndoMarkName(markId30, "Cutting Parameters")

Try
' Expression is still in use.
workPart.Expressions.Delete(expression4)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

Try
' Expression is still in use.
workPart.Expressions.Delete(expression3)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

plane1.DestroyPlane()

workPart.Expressions.Delete(expression5)

workPart.Expressions.Delete(expression6)

theSession.DeleteUndoMark(markId30, Nothing)

Dim nXObject7 As NXObject
nXObject7 = faceMillingBuilder4.Commit()

Dim objects1(0) As CAM.CAMObject
Dim faceMilling5 As CAM.FaceMilling = CType(nXObject7, CAM.FaceMilling)

objects1(0) = faceMilling5
workPart.CAMSetup.GenerateToolPath(objects1)

Dim markId33 As Session.UndoMarkId
markId33 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Face Milling")

theSession.DeleteUndoMark(markId33, Nothing)

Dim markId34 As Session.UndoMarkId
markId34 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Face Milling")

theSession.DeleteUndoMark(markId34, Nothing)

theSession.SetUndoMarkName(markId26, "Face Milling")

faceMillingBuilder4.Destroy()

theSession.DeleteUndoMark(markId26, Nothing)

Dim markId35 As Session.UndoMarkId
markId35 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")

Dim faceMillingBuilder5 As CAM.FaceMillingBuilder
faceMillingBuilder5 = workPart.CAMSetup.CAMOperationCollection.CreateFaceMillingBuilder(faceMilling5)

theSession.SetUndoMarkName(markId35, "Face Milling Dialog")

' ----------------------------------------------
' Dialog Begin Face Milling
' ----------------------------------------------
Dim markId36 As Session.UndoMarkId
markId36 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Face Milling")

theSession.DeleteUndoMark(markId36, Nothing)

Dim markId37 As Session.UndoMarkId
markId37 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Face Milling")

Dim nXObject8 As NXObject
nXObject8 = faceMillingBuilder5.Commit()

theSession.DeleteUndoMark(markId37, Nothing)

theSession.SetUndoMarkName(markId35, "Face Milling")

faceMillingBuilder5.Destroy()

theSession.DeleteUndoMark(markId35, Nothing)

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

Do you want the user to be prompted to select a face, or should the journal select a face automatically?

If the journal is selecting the face, what criteria should it use to get the correct one?

sorry for the late reply . Was away for the weekend.
I would like the Journal to select the face and the boundaries automatically.
The criteria should be that the face is the first face perpendicular to the tool direction. There is a dialogue box to select the face and boundaries in the Mill Path generation tool dialogue box. But the selection is somehow bypassed by the journal.