Need help with an experimental learning project

I was wondering if I could get some help creating a specific program. I feel like all the pieces to this experimental project are there I just don’t understand how to put it all together.

As a disclaimer I am still learning how to program in vb and python so I am not as skilled as I would like to be.

Ideally what I want is a program that I can run after I have finished modeling a part and the program will go down the NX hierarchy tree and read the model history and save out to a text file the steps used to create the part, including the information found within the sketches. So that later on I can create a vb form and attach the text to a button and when the vb exe is run within NX I can press that button and it will create that part. I can see that if I record a journal, please see attached journal, that what I want kind of already exists in NX. Journals already records how a part is made and NX lets you replay the journal to recreate a part, so I feel like all the pieces to my experimental project are there I just don’t understand how to put it all together.

Can anyone help?

Below is the journal I recorded of a part all the constraints are automatically generated in this part but I don't think it would matter if they are created by hand or not if the program could just read the model history after the part was finished being made, since the sketches would not be altered at that point.

' NX 9.0.3.4
' Journal created by student on Tue Jun 09 08:45:55 2015 Eastern Daylight Time
'
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->Sketch...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim nullSketch As Sketch = Nothing

Dim sketchInPlaceBuilder1 As SketchInPlaceBuilder
sketchInPlaceBuilder1 = workPart.Sketches.CreateNewSketchInPlaceBuilder(nullSketch)

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)

Dim sketchAlongPathBuilder1 As SketchAlongPathBuilder
sketchAlongPathBuilder1 = workPart.Sketches.CreateSketchAlongPathBuilder(nullSketch)

sketchAlongPathBuilder1.PlaneLocation.Expression.RightHandSide = "0"

theSession.SetUndoMarkName(markId1, "Create Sketch Dialog")

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

theSession.DeleteUndoMark(markId2, Nothing)

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Create Sketch")

theSession.Preferences.Sketch.CreateInferredConstraints = True

theSession.Preferences.Sketch.ContinuousAutoDimensioning = True

theSession.Preferences.Sketch.DimensionLabel = Preferences.SketchPreferences.DimensionLabelType.Expression

theSession.Preferences.Sketch.TextSizeFixed = True

theSession.Preferences.Sketch.FixedTextSize = 3.0

theSession.Preferences.Sketch.ConstraintSymbolSize = 3.0

theSession.Preferences.Sketch.DisplayObjectColor = False

theSession.Preferences.Sketch.DisplayObjectName = True

Dim nXObject1 As NXObject
nXObject1 = sketchInPlaceBuilder1.Commit()

Dim sketch1 As Sketch = CType(nXObject1, Sketch)

Dim feature1 As Features.Feature
feature1 = sketch1.Feature

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

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId4)

sketch1.Activate(Sketch.ViewReorient.True)

theSession.DeleteUndoMark(markId3, Nothing)

theSession.SetUndoMarkName(markId1, "Create Sketch")

sketchInPlaceBuilder1.Destroy()

sketchAlongPathBuilder1.Destroy()

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

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

' ----------------------------------------------
' Menu: Insert->Sketch Curve->Circle...
' ----------------------------------------------
Dim markId5 As Session.UndoMarkId
markId5 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Profile short list")

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

theSession.SetUndoMarkVisibility(markId6, "Curve", Session.MarkVisibility.Visible)

Dim nXMatrix1 As NXMatrix
nXMatrix1 = theSession.ActiveSketch.Orientation

Dim center1 As Point3d = New Point3d(-157.666886234165, 284.841591640025, 0.0)
Dim arc1 As Arc
arc1 = workPart.Curves.CreateArc(center1, nXMatrix1, 172.502648647445, 0.0, ( 360.0 * Math.Pi/180.0 ))

theSession.ActiveSketch.AddGeometry(arc1, Sketch.InferConstraintsOption.InferNoConstraints)

Dim dimObject1_1 As Sketch.DimensionGeometry
dimObject1_1.Geometry = arc1
dimObject1_1.AssocType = Sketch.AssocType.Midpoint
dimObject1_1.AssocValue = 0
dimObject1_1.HelpPoint.X = 0.0
dimObject1_1.HelpPoint.Y = 0.0
dimObject1_1.HelpPoint.Z = 0.0
Dim nullNXObject As NXObject = Nothing

dimObject1_1.View = nullNXObject
Dim dimOrigin1 As Point3d = New Point3d(-157.666886234165, 301.706865460943, 0.0)
Dim nullExpression As Expression = Nothing

Dim sketchDimensionalConstraint1 As SketchDimensionalConstraint
sketchDimensionalConstraint1 = theSession.ActiveSketch.CreateDiameterDimension(dimObject1_1, dimOrigin1, nullExpression, Sketch.DimensionOption.CreateAsAutomatic)

Dim dimension1 As Annotations.Dimension
dimension1 = sketchDimensionalConstraint1.AssociatedDimension

Dim expression3 As Expression
expression3 = sketchDimensionalConstraint1.AssociatedExpression

theSession.ActiveSketch.Update()

' ----------------------------------------------
' Dialog Begin Circle
' ----------------------------------------------
Dim markId7 As Session.UndoMarkId
markId7 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Curve")

theSession.SetUndoMarkVisibility(markId7, "Curve", Session.MarkVisibility.Visible)

Dim nXMatrix2 As NXMatrix
nXMatrix2 = theSession.ActiveSketch.Orientation

Dim center2 As Point3d = New Point3d(96.6825245775542, -103.375930125231, 0.0)
Dim arc2 As Arc
arc2 = workPart.Curves.CreateArc(center2, nXMatrix2, 167.234294048475, 0.0, ( 360.0 * Math.Pi/180.0 ))

theSession.ActiveSketch.AddGeometry(arc2, Sketch.InferConstraintsOption.InferNoConstraints)

Dim dimObject1_2 As Sketch.DimensionGeometry
dimObject1_2.Geometry = arc2
dimObject1_2.AssocType = Sketch.AssocType.Midpoint
dimObject1_2.AssocValue = 0
dimObject1_2.HelpPoint.X = 0.0
dimObject1_2.HelpPoint.Y = 0.0
dimObject1_2.HelpPoint.Z = 0.0
dimObject1_2.View = nullNXObject
Dim dimOrigin2 As Point3d = New Point3d(96.6825245775542, -86.510656304313, 0.0)
Dim sketchDimensionalConstraint2 As SketchDimensionalConstraint
sketchDimensionalConstraint2 = theSession.ActiveSketch.CreateDiameterDimension(dimObject1_2, dimOrigin2, nullExpression, Sketch.DimensionOption.CreateAsAutomatic)

Dim dimension2 As Annotations.Dimension
dimension2 = sketchDimensionalConstraint2.AssociatedDimension

Dim expression4 As Expression
expression4 = sketchDimensionalConstraint2.AssociatedExpression

theSession.ActiveSketch.Update()

' ----------------------------------------------
' Dialog Begin Circle
' ----------------------------------------------
' ----------------------------------------------
' Menu: Insert->Sketch Curve->Rectangle...
' ----------------------------------------------
Dim markId8 As Session.UndoMarkId
markId8 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Profile short list")

Dim markId9 As Session.UndoMarkId
markId9 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Create Rectangle")

theSession.SetUndoMarkVisibility(markId9, "Create Rectangle", Session.MarkVisibility.Visible)

' ----------------------------------------------
' Creating rectangle using By 2 Points method
' ----------------------------------------------
Dim startPoint1 As Point3d = New Point3d(-140.0, 170.0, 0.0)
Dim endPoint1 As Point3d = New Point3d(58.0095147465326, 170.0, 0.0)
Dim line1 As Line
line1 = workPart.Curves.CreateLine(startPoint1, endPoint1)

Dim startPoint2 As Point3d = New Point3d(58.0095147465326, 170.0, 0.0)
Dim endPoint2 As Point3d = New Point3d(58.0095147465326, -103.375930125231, 0.0)
Dim line2 As Line
line2 = workPart.Curves.CreateLine(startPoint2, endPoint2)

Dim startPoint3 As Point3d = New Point3d(58.0095147465326, -103.375930125231, 0.0)
Dim endPoint3 As Point3d = New Point3d(-140.0, -103.375930125231, 0.0)
Dim line3 As Line
line3 = workPart.Curves.CreateLine(startPoint3, endPoint3)

Dim startPoint4 As Point3d = New Point3d(-140.0, -103.375930125231, 0.0)
Dim endPoint4 As Point3d = New Point3d(-140.0, 170.0, 0.0)
Dim line4 As Line
line4 = workPart.Curves.CreateLine(startPoint4, endPoint4)

theSession.ActiveSketch.AddGeometry(line1, Sketch.InferConstraintsOption.InferNoConstraints)

theSession.ActiveSketch.AddGeometry(line2, Sketch.InferConstraintsOption.InferNoConstraints)

theSession.ActiveSketch.AddGeometry(line3, Sketch.InferConstraintsOption.InferNoConstraints)

theSession.ActiveSketch.AddGeometry(line4, Sketch.InferConstraintsOption.InferNoConstraints)

Dim geom1_1 As Sketch.ConstraintGeometry
geom1_1.Geometry = line1
geom1_1.PointType = Sketch.ConstraintPointType.EndVertex
geom1_1.SplineDefiningPointIndex = 0
Dim geom2_1 As Sketch.ConstraintGeometry
geom2_1.Geometry = line2
geom2_1.PointType = Sketch.ConstraintPointType.StartVertex
geom2_1.SplineDefiningPointIndex = 0
Dim sketchGeometricConstraint1 As SketchGeometricConstraint
sketchGeometricConstraint1 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_1, geom2_1)

Dim geom1_2 As Sketch.ConstraintGeometry
geom1_2.Geometry = line2
geom1_2.PointType = Sketch.ConstraintPointType.EndVertex
geom1_2.SplineDefiningPointIndex = 0
Dim geom2_2 As Sketch.ConstraintGeometry
geom2_2.Geometry = line3
geom2_2.PointType = Sketch.ConstraintPointType.StartVertex
geom2_2.SplineDefiningPointIndex = 0
Dim sketchGeometricConstraint2 As SketchGeometricConstraint
sketchGeometricConstraint2 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_2, geom2_2)

Dim geom1_3 As Sketch.ConstraintGeometry
geom1_3.Geometry = line3
geom1_3.PointType = Sketch.ConstraintPointType.EndVertex
geom1_3.SplineDefiningPointIndex = 0
Dim geom2_3 As Sketch.ConstraintGeometry
geom2_3.Geometry = line4
geom2_3.PointType = Sketch.ConstraintPointType.StartVertex
geom2_3.SplineDefiningPointIndex = 0
Dim sketchGeometricConstraint3 As SketchGeometricConstraint
sketchGeometricConstraint3 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_3, geom2_3)

Dim geom1_4 As Sketch.ConstraintGeometry
geom1_4.Geometry = line4
geom1_4.PointType = Sketch.ConstraintPointType.EndVertex
geom1_4.SplineDefiningPointIndex = 0
Dim geom2_4 As Sketch.ConstraintGeometry
geom2_4.Geometry = line1
geom2_4.PointType = Sketch.ConstraintPointType.StartVertex
geom2_4.SplineDefiningPointIndex = 0
Dim sketchGeometricConstraint4 As SketchGeometricConstraint
sketchGeometricConstraint4 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_4, geom2_4)

Dim geom1 As Sketch.ConstraintGeometry
geom1.Geometry = line1
geom1.PointType = Sketch.ConstraintPointType.None
geom1.SplineDefiningPointIndex = 0
Dim sketchGeometricConstraint5 As SketchGeometricConstraint
sketchGeometricConstraint5 = theSession.ActiveSketch.CreateHorizontalConstraint(geom1)

Dim conGeom1_1 As Sketch.ConstraintGeometry
conGeom1_1.Geometry = line1
conGeom1_1.PointType = Sketch.ConstraintPointType.None
conGeom1_1.SplineDefiningPointIndex = 0
Dim conGeom2_1 As Sketch.ConstraintGeometry
conGeom2_1.Geometry = line2
conGeom2_1.PointType = Sketch.ConstraintPointType.None
conGeom2_1.SplineDefiningPointIndex = 0
Dim sketchGeometricConstraint6 As SketchGeometricConstraint
sketchGeometricConstraint6 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_1, conGeom2_1)

Dim conGeom1_2 As Sketch.ConstraintGeometry
conGeom1_2.Geometry = line2
conGeom1_2.PointType = Sketch.ConstraintPointType.None
conGeom1_2.SplineDefiningPointIndex = 0
Dim conGeom2_2 As Sketch.ConstraintGeometry
conGeom2_2.Geometry = line3
conGeom2_2.PointType = Sketch.ConstraintPointType.None
conGeom2_2.SplineDefiningPointIndex = 0
Dim sketchGeometricConstraint7 As SketchGeometricConstraint
sketchGeometricConstraint7 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_2, conGeom2_2)

Dim conGeom1_3 As Sketch.ConstraintGeometry
conGeom1_3.Geometry = line3
conGeom1_3.PointType = Sketch.ConstraintPointType.None
conGeom1_3.SplineDefiningPointIndex = 0
Dim conGeom2_3 As Sketch.ConstraintGeometry
conGeom2_3.Geometry = line4
conGeom2_3.PointType = Sketch.ConstraintPointType.None
conGeom2_3.SplineDefiningPointIndex = 0
Dim sketchGeometricConstraint8 As SketchGeometricConstraint
sketchGeometricConstraint8 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_3, conGeom2_3)

Dim conGeom1_4 As Sketch.ConstraintGeometry
conGeom1_4.Geometry = line4
conGeom1_4.PointType = Sketch.ConstraintPointType.None
conGeom1_4.SplineDefiningPointIndex = 0
Dim conGeom2_4 As Sketch.ConstraintGeometry
conGeom2_4.Geometry = line1
conGeom2_4.PointType = Sketch.ConstraintPointType.None
conGeom2_4.SplineDefiningPointIndex = 0
Dim sketchGeometricConstraint9 As SketchGeometricConstraint
sketchGeometricConstraint9 = theSession.ActiveSketch.CreatePerpendicularConstraint(conGeom1_4, conGeom2_4)

Dim dimObject1_3 As Sketch.DimensionGeometry
dimObject1_3.Geometry = line1
dimObject1_3.AssocType = Sketch.AssocType.StartPoint
dimObject1_3.AssocValue = 0
dimObject1_3.HelpPoint.X = 0.0
dimObject1_3.HelpPoint.Y = 0.0
dimObject1_3.HelpPoint.Z = 0.0
dimObject1_3.View = nullNXObject
Dim dimObject2_1 As Sketch.DimensionGeometry
dimObject2_1.Geometry = line1
dimObject2_1.AssocType = Sketch.AssocType.EndPoint
dimObject2_1.AssocValue = 0
dimObject2_1.HelpPoint.X = 0.0
dimObject2_1.HelpPoint.Y = 0.0
dimObject2_1.HelpPoint.Z = 0.0
dimObject2_1.View = nullNXObject
Dim dimOrigin3 As Point3d = New Point3d(-40.9952426267337, 119.404178537246, 0.0)
Dim sketchDimensionalConstraint3 As SketchDimensionalConstraint
sketchDimensionalConstraint3 = theSession.ActiveSketch.CreateDimension(Sketch.ConstraintType.ParallelDim, dimObject1_3, dimObject2_1, dimOrigin3, nullExpression, Sketch.DimensionOption.CreateAsAutomatic)

Dim sketchHelpedDimensionalConstraint1 As SketchHelpedDimensionalConstraint = CType(sketchDimensionalConstraint3, SketchHelpedDimensionalConstraint)

Dim dimension3 As Annotations.Dimension
dimension3 = sketchHelpedDimensionalConstraint1.AssociatedDimension

Dim expression5 As Expression
expression5 = sketchHelpedDimensionalConstraint1.AssociatedExpression

Dim dimObject1_4 As Sketch.DimensionGeometry
dimObject1_4.Geometry = line2
dimObject1_4.AssocType = Sketch.AssocType.StartPoint
dimObject1_4.AssocValue = 0
dimObject1_4.HelpPoint.X = 0.0
dimObject1_4.HelpPoint.Y = 0.0
dimObject1_4.HelpPoint.Z = 0.0
dimObject1_4.View = nullNXObject
Dim dimObject2_2 As Sketch.DimensionGeometry
dimObject2_2.Geometry = line2
dimObject2_2.AssocType = Sketch.AssocType.EndPoint
dimObject2_2.AssocValue = 0
dimObject2_2.HelpPoint.X = 0.0
dimObject2_2.HelpPoint.Y = 0.0
dimObject2_2.HelpPoint.Z = 0.0
dimObject2_2.View = nullNXObject
Dim dimOrigin4 As Point3d = New Point3d(7.4136932837786, 33.3120349373845, 0.0)
Dim sketchDimensionalConstraint4 As SketchDimensionalConstraint
sketchDimensionalConstraint4 = theSession.ActiveSketch.CreateDimension(Sketch.ConstraintType.ParallelDim, dimObject1_4, dimObject2_2, dimOrigin4, nullExpression, Sketch.DimensionOption.CreateAsAutomatic)

Dim sketchHelpedDimensionalConstraint2 As SketchHelpedDimensionalConstraint = CType(sketchDimensionalConstraint4, SketchHelpedDimensionalConstraint)

Dim dimension4 As Annotations.Dimension
dimension4 = sketchHelpedDimensionalConstraint2.AssociatedDimension

Dim expression6 As Expression
expression6 = sketchHelpedDimensionalConstraint2.AssociatedExpression

theSession.Preferences.Sketch.AutoDimensionsToArcCenter = False

theSession.ActiveSketch.Update()

theSession.Preferences.Sketch.AutoDimensionsToArcCenter = True

Dim geoms1(3) As SmartObject
geoms1(0) = line1
geoms1(1) = line2
geoms1(2) = line3
geoms1(3) = line4
theSession.ActiveSketch.UpdateConstraintDisplay(geoms1)

Dim geoms2(3) As SmartObject
geoms2(0) = line1
geoms2(1) = line2
geoms2(2) = line3
geoms2(3) = line4
theSession.ActiveSketch.UpdateDimensionDisplay(geoms2)

' ----------------------------------------------
' Menu: Edit->Sketch Curve->Quick Trim...
' ----------------------------------------------
Dim markId10 As Session.UndoMarkId
markId10 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim sketchQuickTrimBuilder1 As SketchQuickTrimBuilder
sketchQuickTrimBuilder1 = workPart.Sketches.CreateQuickTrimBuilder()

theSession.SetUndoMarkName(markId10, "Quick Trim Dialog")

Dim point1 As Point3d = New Point3d(-69.9089023868469, 170.0, 0.0)
Dim added1 As Boolean
added1 = sketchQuickTrimBuilder1.TrimmedCurves.Add(line1, workPart.ModelingViews.WorkView, point1)

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

Dim added2 As Boolean
added2 = sketchQuickTrimBuilder1.BoundaryObjects.Add(arc1)

sketchQuickTrimBuilder1.ExtendBound = False

Dim nXObject2 As NXObject
nXObject2 = sketchQuickTrimBuilder1.Commit()

sketchQuickTrimBuilder1.ExtendBound = True

sketchQuickTrimBuilder1.BoundaryObjects.Clear()

sketchQuickTrimBuilder1.Destroy()

theSession.DeleteUndoMark(markId11, Nothing)

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

Dim sketchQuickTrimBuilder2 As SketchQuickTrimBuilder
sketchQuickTrimBuilder2 = workPart.Sketches.CreateQuickTrimBuilder()

sketchQuickTrimBuilder2.ExtendBound = True

Dim point2 As Point3d = New Point3d(-140.0, 140.561516501214, 0.0)
Dim added3 As Boolean
added3 = sketchQuickTrimBuilder2.TrimmedCurves.Add(line4, workPart.ModelingViews.WorkView, point2)

theSession.SetUndoMarkVisibility(markId12, Nothing, Session.MarkVisibility.Visible)

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

Dim added4 As Boolean
added4 = sketchQuickTrimBuilder2.BoundaryObjects.Add(arc1)

sketchQuickTrimBuilder2.ExtendBound = False

Dim nXObject3 As NXObject
nXObject3 = sketchQuickTrimBuilder2.Commit()

sketchQuickTrimBuilder2.ExtendBound = True

sketchQuickTrimBuilder2.BoundaryObjects.Clear()

sketchQuickTrimBuilder2.Destroy()

theSession.DeleteUndoMark(markId13, Nothing)

Dim markId14 As Session.UndoMarkId
markId14 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Quick Trim")

Dim sketchQuickTrimBuilder3 As SketchQuickTrimBuilder
sketchQuickTrimBuilder3 = workPart.Sketches.CreateQuickTrimBuilder()

sketchQuickTrimBuilder3.ExtendBound = True

Dim point3 As Point3d = New Point3d(-91.0347492870739, 125.822782077033, 0.0)
Dim added5 As Boolean
added5 = sketchQuickTrimBuilder3.TrimmedCurves.Add(arc1, workPart.ModelingViews.WorkView, point3)

theSession.SetUndoMarkVisibility(markId14, Nothing, Session.MarkVisibility.Visible)

Dim markId15 As Session.UndoMarkId
markId15 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Quick Trim")

Dim added6 As Boolean
added6 = sketchQuickTrimBuilder3.BoundaryObjects.Add(line4)

Dim added7 As Boolean
added7 = sketchQuickTrimBuilder3.BoundaryObjects.Add(line1)

sketchQuickTrimBuilder3.ExtendBound = False

Dim nXObject4 As NXObject
nXObject4 = sketchQuickTrimBuilder3.Commit()

sketchQuickTrimBuilder3.ExtendBound = True

sketchQuickTrimBuilder3.BoundaryObjects.Clear()

sketchQuickTrimBuilder3.Destroy()

theSession.DeleteUndoMark(markId15, Nothing)

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

Dim sketchQuickTrimBuilder4 As SketchQuickTrimBuilder
sketchQuickTrimBuilder4 = workPart.Sketches.CreateQuickTrimBuilder()

sketchQuickTrimBuilder4.ExtendBound = True

Dim point4 As Point3d = New Point3d(-10.4119641852751, -103.375930125231, 0.0)
Dim added8 As Boolean
added8 = sketchQuickTrimBuilder4.TrimmedCurves.Add(line3, workPart.ModelingViews.WorkView, point4)

theSession.SetUndoMarkVisibility(markId16, Nothing, Session.MarkVisibility.Visible)

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

Dim added9 As Boolean
added9 = sketchQuickTrimBuilder4.BoundaryObjects.Add(arc2)

sketchQuickTrimBuilder4.ExtendBound = False

Dim nXObject5 As NXObject
nXObject5 = sketchQuickTrimBuilder4.Commit()

sketchQuickTrimBuilder4.ExtendBound = True

sketchQuickTrimBuilder4.BoundaryObjects.Clear()

sketchQuickTrimBuilder4.Destroy()

theSession.DeleteUndoMark(markId17, Nothing)

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

Dim sketchQuickTrimBuilder5 As SketchQuickTrimBuilder
sketchQuickTrimBuilder5 = workPart.Sketches.CreateQuickTrimBuilder()

sketchQuickTrimBuilder5.ExtendBound = True

Dim point5 As Point3d = New Point3d(-69.2774485985539, -83.4811925475942, 0.0)
Dim added10 As Boolean
added10 = sketchQuickTrimBuilder5.TrimmedCurves.Add(arc2, workPart.ModelingViews.WorkView, point5)

theSession.SetUndoMarkVisibility(markId18, Nothing, Session.MarkVisibility.Visible)

Dim markId19 As Session.UndoMarkId
markId19 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Quick Trim")

Dim added11 As Boolean
added11 = sketchQuickTrimBuilder5.BoundaryObjects.Add(line2)

Dim added12 As Boolean
added12 = sketchQuickTrimBuilder5.BoundaryObjects.Add(line3)

sketchQuickTrimBuilder5.ExtendBound = False

Dim nXObject6 As NXObject
nXObject6 = sketchQuickTrimBuilder5.Commit()

sketchQuickTrimBuilder5.ExtendBound = True

sketchQuickTrimBuilder5.BoundaryObjects.Clear()

sketchQuickTrimBuilder5.Destroy()

theSession.DeleteUndoMark(markId19, Nothing)

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

Dim sketchQuickTrimBuilder6 As SketchQuickTrimBuilder
sketchQuickTrimBuilder6 = workPart.Sketches.CreateQuickTrimBuilder()

sketchQuickTrimBuilder6.ExtendBound = True

Dim point6 As Point3d = New Point3d(58.0095147465326, -70.6526141143664, 0.0)
Dim added13 As Boolean
added13 = sketchQuickTrimBuilder6.TrimmedCurves.Add(line2, workPart.ModelingViews.WorkView, point6)

theSession.SetUndoMarkVisibility(markId20, Nothing, Session.MarkVisibility.Visible)

Dim markId21 As Session.UndoMarkId
markId21 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Quick Trim")

Dim added14 As Boolean
added14 = sketchQuickTrimBuilder6.BoundaryObjects.Add(arc2)

sketchQuickTrimBuilder6.ExtendBound = False

Dim nXObject7 As NXObject
nXObject7 = sketchQuickTrimBuilder6.Commit()

sketchQuickTrimBuilder6.ExtendBound = True

sketchQuickTrimBuilder6.BoundaryObjects.Clear()

sketchQuickTrimBuilder6.Destroy()

theSession.DeleteUndoMark(markId21, Nothing)

Dim markId22 As Session.UndoMarkId
markId22 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Quick Trim")

Dim sketchQuickTrimBuilder7 As SketchQuickTrimBuilder
sketchQuickTrimBuilder7 = workPart.Sketches.CreateQuickTrimBuilder()

sketchQuickTrimBuilder7.ExtendBound = True

theSession.SetUndoMarkName(markId10, "Quick Trim")

sketchQuickTrimBuilder7.Destroy()

theSession.DeleteUndoMark(markId22, Nothing)

' ----------------------------------------------
' Menu: File->Finish Sketch
' ----------------------------------------------
theSession.ActiveSketch.Deactivate(Sketch.ViewReorient.False, Sketch.UpdateLevel.Model)

' ----------------------------------------------
' Menu: Insert->Design Feature->Extrude...
' ----------------------------------------------
Dim markId23 As Session.UndoMarkId
markId23 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim nullFeatures_Feature As Features.Feature = Nothing

If Not workPart.Preferences.Modeling.GetHistoryMode Then
Throw(New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
End If

Dim extrudeBuilder1 As Features.ExtrudeBuilder
extrudeBuilder1 = workPart.Features.CreateExtrudeBuilder(nullFeatures_Feature)

Dim section1 As Section
section1 = workPart.Sections.CreateSection(0.0095, 0.01, 0.5)

extrudeBuilder1.Section = section1

extrudeBuilder1.AllowSelfIntersectingSection(True)

Dim unit2 As Unit
unit2 = extrudeBuilder1.Draft.FrontDraftAngle.Units

Dim expression7 As Expression
expression7 = workPart.Expressions.CreateSystemExpressionWithUnits("2.00", unit2)

extrudeBuilder1.DistanceTolerance = 0.01

extrudeBuilder1.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Create

Dim targetBodies1(0) As Body
Dim nullBody As Body = Nothing

targetBodies1(0) = nullBody
extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies1)

extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = "0"

extrudeBuilder1.Limits.EndExtend.Value.RightHandSide = "25"

extrudeBuilder1.Offset.StartOffset.RightHandSide = "0"

extrudeBuilder1.Offset.EndOffset.RightHandSide = "5"

Dim smartVolumeProfileBuilder1 As GeometricUtilities.SmartVolumeProfileBuilder
smartVolumeProfileBuilder1 = extrudeBuilder1.SmartVolumeProfile

smartVolumeProfileBuilder1.OpenProfileSmartVolumeOption = False

smartVolumeProfileBuilder1.CloseProfileRule = GeometricUtilities.SmartVolumeProfileBuilder.CloseProfileRuleType.Fci

theSession.SetUndoMarkName(markId23, "Extrude Dialog")

extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = "0"

extrudeBuilder1.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Create

Dim targetBodies2(0) As Body
targetBodies2(0) = nullBody
extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies2)

extrudeBuilder1.Limits.EndExtend.Value.RightHandSide = "25"

extrudeBuilder1.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Create

Dim targetBodies3(0) As Body
targetBodies3(0) = nullBody
extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies3)

extrudeBuilder1.Draft.FrontDraftAngle.RightHandSide = "2"

Dim expression8 As Expression
expression8 = extrudeBuilder1.Draft.FrontDraftAngle

expression8.RightHandSide = "2"

extrudeBuilder1.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Create

Dim targetBodies4(0) As Body
targetBodies4(0) = nullBody
extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies4)

extrudeBuilder1.Draft.BackDraftAngle.RightHandSide = "2"

Dim expression9 As Expression
expression9 = extrudeBuilder1.Draft.BackDraftAngle

expression9.RightHandSide = "2"

extrudeBuilder1.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Create

Dim targetBodies5(0) As Body
targetBodies5(0) = nullBody
extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies5)

extrudeBuilder1.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Create

Dim targetBodies6(0) As Body
targetBodies6(0) = nullBody
extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies6)

extrudeBuilder1.Offset.StartOffset.RightHandSide = "0"

Dim expression10 As Expression
expression10 = extrudeBuilder1.Offset.StartOffset

expression10.RightHandSide = "0"

extrudeBuilder1.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Create

Dim targetBodies7(0) As Body
targetBodies7(0) = nullBody
extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies7)

extrudeBuilder1.Offset.EndOffset.RightHandSide = "5"

Dim expression11 As Expression
expression11 = extrudeBuilder1.Offset.EndOffset

expression11.RightHandSide = "5"

extrudeBuilder1.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Create

Dim targetBodies8(0) As Body
targetBodies8(0) = nullBody
extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies8)

section1.DistanceTolerance = 0.01

section1.ChainingTolerance = 0.0095

section1.SetAllowedEntityTypes(Section.AllowTypes.OnlyCurves)

Dim markId24 As Session.UndoMarkId
markId24 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "section mark")

Dim markId25 As Session.UndoMarkId
markId25 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, Nothing)

Dim features1(0) As Features.Feature
Dim sketchFeature1 As Features.SketchFeature = CType(feature1, Features.SketchFeature)

features1(0) = sketchFeature1
Dim curveFeatureRule1 As CurveFeatureRule
curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1)

section1.AllowSelfIntersection(True)

Dim rules1(0) As SelectionIntentRule
rules1(0) = curveFeatureRule1
Dim helpPoint1 As Point3d = New Point3d(-240.613633738662, 435.997817999959, 0.0)
section1.AddToSection(rules1, arc1, nullNXObject, nullNXObject, helpPoint1, Section.Mode.Create, False)

theSession.DeleteUndoMark(markId25, Nothing)

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

extrudeBuilder1.Direction = direction1

theSession.DeleteUndoMark(markId24, Nothing)

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

theSession.DeleteUndoMark(markId26, Nothing)

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

extrudeBuilder1.ParentFeatureInternal = False

Dim feature2 As Features.Feature
feature2 = extrudeBuilder1.CommitFeature()

theSession.DeleteUndoMark(markId27, Nothing)

theSession.SetUndoMarkName(markId23, "Extrude")

Dim expression12 As Expression = extrudeBuilder1.Limits.StartExtend.Value

Dim expression13 As Expression = extrudeBuilder1.Limits.EndExtend.Value

extrudeBuilder1.Destroy()

workPart.Expressions.Delete(expression7)

Dim rotMatrix1 As Matrix3x3
rotMatrix1.Xx = 0.919552393727839
rotMatrix1.Xy = -0.374259734500406
rotMatrix1.Xz = 0.119804199930916
rotMatrix1.Yx = 0.042751066957655
rotMatrix1.Yy = 0.398337055458549
rotMatrix1.Yz = 0.916242291385087
rotMatrix1.Zx = -0.390635048943875
rotMatrix1.Zy = -0.837411034904782
rotMatrix1.Zz = 0.382291795826588
Dim translation1 As Point3d = New Point3d(31.1066841265851, 46.6945700846506, 73.6566024201247)
workPart.ModelingViews.WorkView.SetRotationTranslationScale(rotMatrix1, translation1, 0.177880301965753)

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

End Sub
End Module

If you have modeled a part that you want to use again later, why not just save the part as a template so you can easily create new parts based on it? I don't see what is gained by rebuilding a given part from scratch.

If I save a part that is modeled in nx can I at a later time go back into the sketches that defined the shape of the part and edit them within the NX sketching system, does the template save the model history tree? There are many reason for getting the model history tree including how the sketches are made. There are many reasons why I want to be able to rebuild a part from 'scratch', there are different tests I want to run at a later time but the main thing is that I want to learn how to build a form in visual studio and be able to feed the vb code from a button I make into NX. I could go in depth into all the individual reasons for why each part of this project is important and how they all tie in together but it just all boils down to the same thing, I am learning how to program in NX and if I could figure out how to do this specific project a boatload of other sub projects that I would like to do would be easier to run/play with.

I know this project has many components in it. How do I read the model history and record what is there? How do I read the individual attributes or each item in the history, such as the extrude distance and unit type? How do I read the shape of the sketch and the constraints on it? how do I save all that information to a text file? How do I get a button from an exe to push those instructions into nx to essentially replay the macro of the creation of the part.

I know how to record a journal and I can record the journal of the part being created I can also see that the journal has the information I want for other research questions I have but I just don’t understand how to put the parts together for what I want to make.

just a noob trying to learn how to program in vb and python for NX

"If I save a part that is modeled in nx can I at a later time go back into the sketches that defined the shape of the part and edit them within the NX sketching system, does the template save the model history tree?"

Yes.
When you save the part as a template it still acts just like a part file. New files created that are based on the template will have the full history and act as normal parts. The exception is: when you press the 'save' button, it will prompt you for a new file name (it won't let you overwrite the template file). The new file will be separate from the template, any changes made in the new file will only exist in the new file.

Re-creating the file from scratch based on the part history will be very difficult. For a simple example, imagine creating a block and applying a chamfer to one of the edges. Re-creating the block is fairly straightforward, but figuring out which edge to apply the chamfer to is more difficult. If you record a journal to apply the original chamfer feature, it will record an edge or face ID; however, the new file will have different edge and face ID's. You'd need an alternative method to determine which edge on the original model the chamfer was applied to and find the corresponding edge in your new model.

Reuse is more practical than starting from scratch in this case.

Part of something I want to study is how people built parts. As a student we have about 30 projects that we build in NX so part of the reason I want to be able to read an already existing model tree and export the information of how it is made is that if I can get a set of students, like 120 students, to give me their projects then i can quickly analyze different statistics as to how they approached the creation of building a specific model. This is just one example of what this project will teach me.

Since I may not be able to find anyone with the skills needed to help me program this project do you know of any books that show how to program for NX?

just a noob trying to learn how to program in vb and python for NX

I know of no books on programming for NX; that's part of the reason why this website was started. If you find such a book, please let me know, I'll add a link to the "resources" page.

If all you want is overall stats on how a particular part was made, such as the number of extrudes, number of blends, overall number of features created, etc etc; that is fairly easy to accomplish. You can iterate through a part's .Features collection to get information about each feature in the tree.

I replied on the wrong field....i guess now I need to see if I can delete my posts on this forum.

The problem with just using the overall stat option is that these parts are already known. Given part 'A' I know that it has exactly 12 holes and 3 edge blends, or something to that nature depending on the part that was built. What can be analyzed based on a program that can read the model history tree is how a person thinks, if they see things more of a top-down vs bottom-up.

Perhaps the problem with this project is capable of doing so much for like 16 other projects that I want to work on.

Is the problem that there is no access to the model history tree? Is there no way to take a journal and make it so that an vb button can play the journal?

just a noob trying to learn how to program in vb and python for NX

Accessing the feature history is the easy part. Once you have a reference to a part, you can access the features by iterating through the "part.Features" collection.

The difficult (though not necessarily impossible) part would be extracting enough information into a text file and later parsing that information to build the part from scratch. There can be many relationships within and between part files that will be difficult to capture and re-create.

I'd suggest breaking this project into smaller chunks; get each chunk to work independently then combine them together to get what you need. For instance, you might start by learning how to iterate through the feature tree and write some information about each feature to a text file. That's a good starting point for learning about the NX API, and something that you will be able to build on for your proposed project.

I also meant to mention:
If you are interested in how someone built a particular model, you can use the "feature playback" command within interactive NX. This will allow you to see step by step how the model was built. As you step through the model, the graphics window will update to show what the model looked like at that particular step. In the NX menu use, Edit -> feature -> playback.