Learn NX-OPEN with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
1
Create a New Part (NXOpen)
Imports NXOpen
Imports NXOpen.UF
Module NXModule
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim part As Part
part = theSession.Parts.NewDisplay("NewPart", Part.Units.Millimeters)
End Sub
End Module
Opens a new part document in NX via NXOpen API.
2
Create a Sketch on XY Plane
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim sketches As Sketches = workPart.Sketches
Dim xyPlane As Plane = workPart.Planes.FindObject("XY Plane")
Dim sketch As Sketch = sketches.CreateSketch(xyPlane)
Creates a new sketch on the XY plane in the active part.
3
Draw a Line in Sketch
Dim sketchCurve As SketchLine = sketch.CreateLine(0, 0, 0.1, 0.1)
Adds a line segment to the current sketch.
4
Draw a Circle in Sketch
Dim sketchCircle As SketchCircle = sketch.CreateCircleByRadius(0, 0, 0, 0.05)
Creates a circle with a center and radius in a sketch.
5
Extrude a Sketch
Dim extrudeBuilder As ExtrudeFeatureBuilder = workPart.Features.CreateExtrudeFeatureBuilder(sketch)
extrudeBuilder.SetDistance(0.1, NXOpen.SmartObject.UpdateOption.AfterModeling)
extrudeBuilder.CommitFeature()
extrudeBuilder.Destroy()
Extrudes the selected sketch to create a 3D solid body.
6
Create a Rectangle Sketch
Dim l1 As SketchLine = sketch.CreateLine(0, 0, 0.1, 0)
Dim l2 As SketchLine = sketch.CreateLine(0.1, 0, 0.1, 0.05)
Dim l3 As SketchLine = sketch.CreateLine(0.1, 0.05, 0, 0.05)
Dim l4 As SketchLine = sketch.CreateLine(0, 0.05, 0, 0)
Draws a rectangle in a sketch using four lines.
7
Apply Fillet to Edge
Dim edge As Edge = workPart.Bodies.FindObject("Edge1")
Dim filletBuilder As FilletFeatureBuilder = workPart.Features.CreateFilletFeatureBuilder(edge)
filletBuilder.SetRadius(0.01)
filletBuilder.CommitFeature()
filletBuilder.Destroy()
Applies a fillet to a selected edge of a solid body.
8
Add Material to Part
Dim material As Material = workPart.Materials.FindObject("Steel")
workPart.SetMaterial(material)
Assigns a material to the active part.
9
Create Circular Pattern
Dim feature As Feature = workPart.Features.FindObject("Extrude1")
Dim axis As Axis = workPart.Axes.FindObject("Z_Axis")
Dim patternBuilder As PatternFeatureBuilder = workPart.Features.CreatePatternFeatureBuilder(feature)
patternBuilder.SetCircularPattern(axis, 6, 360)
patternBuilder.CommitFeature()
patternBuilder.Destroy()
Patterns a feature in a circular pattern around an axis.
10
Save Part Document
workPart.SaveAs("C:\Users\Public\Documents\NXParts\Part1.prt")
Saves the active part to a specified file path.