0% found this document useful (0 votes)
89 views

Beginners Guide to Learn NXOpen Programming

Uploaded by

Uday Kumar Yadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views

Beginners Guide to Learn NXOpen Programming

Uploaded by

Uday Kumar Yadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

@ParametricKrish

Beginners Guide to Learn


NXOpen Programming
Any Design Engineer Can Learn Without Any Prior Knowledge
Purpose of this ebook
● Introduce newbies to the world of NXOpen automation.
● Make Design Engineers aware of how Journal files are written, which is the first step
toward writing programs in NXOpen.
● Explain NXOpen concepts with simple examples which are easy to understand.

Table of Contents
Purpose of this ebook
Table of Contents
Introduction to NX Open
Unigraphics
NX programming Tools
What is NX Open?
UFUNC or User Function
Programming Language for CAD Automation: C Sharp or Visual Basic .Net
#1
CREATE BLANK PART WITH DRAWING SHEET (C Sharp)
Source code:
Explanation:
#2
UPDATE ALL SOLID EDGE COMPONENTS (Visual Basic .Net)
Purpose:
How to use:
Source Code:
Explanation:
#3
REPORT TOP LEVEL PARTS IN SESSION (Visual Basic .Net)
Purpose:
How to use:
Source Code:
Explanation:
#4
REPORT ALL CUSTOM SYMBOLS (Visual Basic .Net)
Purpose:
How to use:
Source Code:
Explanation:
What is CAD API | Application Programming Interface | Computer Aided Design
#5
UPDATE ALL DRAFTING VIEWS (Visual Basic .Net)
Purpose:
How to use:
Source Code:
Explanation:
What is the Difference Between CAD Developer and Design Automation Engineer?
#6
EXPORT EXPRESSIONS FROM WORK PART (Visual Basic .Net)
Purpose:
How to use:
Source Code:
Explanation:
Stages of Learning CAD Automation / CAD Customization
#7
CLEAN UP WORK PART (Visual Basic .Net)
Purpose:
How to use:
Source code:
Explanation:
#8
SHOW ALL FEATURE DIMENSIONS (Visual Basic .Net)
Purpose:
How to use:
Source code:
Explanation:
CONCLUSION
Attend the NXOpen Programming Masterclass

Introduction to NX Open
Siemens NX does not need an introduction to any Mechanical Design Engineer. Most Design
engineers used it at some point of time.

Unigraphics
NX, formerly known as "Unigraphics", is an advanced high-end CAD/CAM/CAE software. For the
first time in the 1980s, it was considered the industry’s true interactive solid modeling software.

NX programming Tools
NX programming and customization software tool is the innovation that took shape in the early
1990s. NX programming and customization software tools help extend and tailor solution
capabilities to custom needs and also prevent product knowledge, all the way through analysis
and manufacturing processes.

Extras

What is NX Open?
Watch on Youtube - https://youtu.be/4cym4e9Tiqc

UFUNC or User Function


Prior to 2000, this Programming and customization tool was called UFUNC (Stands for User
Function), which was supporting applications developed in Fortran and C Language.
UFUNC was very widely used and popular among industries as a productivity enhancement tool.
It had a very wide user base back then. In order to further widen the user base of the NX
Programming and customization tool, NX has developed the NXOpen .NET API namespace,
which was actually by building wrappers around UFUNC functions. Newer NXOpen .NET API
functions are built directly on top of internal Nx functions.

NXOpen is supporting applications developed in Java, Python, Visual Basic .NET, C# .Net, C/C++
Languages.

Extras

Programming Language for CAD Automation: C Sharp or


Visual Basic .Net
Watch on YouTube - https://youtu.be/-mG3Cd7Bjdw

#1
CREATE BLANK PART WITH DRAWING SHEET (C
Sharp)

Source code:

using System;
using NXOpen;

public class create_blank_part_with_drawing_sheet


{
public static void Main(string[] args)
{
Session theSession = Session.GetSession();

FileNew fileNew1;
fileNew1 = theSession.Parts.FileNew();
fileNew1.TemplateFileName = "Blank";
fileNew1.Application = FileNewApplication.Gateway;
fileNew1.Units = NXOpen.Part.Units.Millimeters;
fileNew1.NewFileName = @"C:\temp\test.prt";
fileNew1.UseBlankTemplate = true;
fileNew1.MakeDisplayedPart = true;
NXObject nXObject1 = fileNew1.Commit();
fileNew1.Destroy();

Part workPart = theSession.Parts.Work;


Part displayPart = theSession.Parts.Display;

NXOpen.Drawings.DrawingSheet nullDrawings_DrawingSheet = null;


NXOpen.Drawings.DrawingSheetBuilder drawingSheetBuilder1;
drawingSheetBuilder1 =
workPart.DrawingSheets.DrawingSheetBuilder(nullDrawings_DrawingSheet)
;
drawingSheetBuilder1.Option =
NXOpen.Drawings.DrawingSheetBuilder.SheetOption.StandardSize;
drawingSheetBuilder1.Units =
NXOpen.Drawings.DrawingSheetBuilder.SheetUnits.Metric;
drawingSheetBuilder1.StandardMetricScale =
NXOpen.Drawings.DrawingSheetBuilder.SheetStandardMetricScale.S11;
drawingSheetBuilder1.Height = 210.0;
drawingSheetBuilder1.Length = 297.0;
drawingSheetBuilder1.ProjectionAngle =
NXOpen.Drawings.DrawingSheetBuilder.SheetProjectionAngle.First;

NXObject nXObject2 = drawingSheetBuilder1.Commit();


drawingSheetBuilder1.Destroy();

// Application Switch will be performed AFTER program ends, see Docs.


UI.GetUI().MenuBarManager.ApplicationSwitchRequest("UG_APP_DRAFTING")
;

// Part is saved but Application is NOT Drafting yet!


displayPart.Save(BasePart.SaveComponents.False,
BasePart.CloseAfterSave.False);
}

public static int GetUnloadOption(string dummy) { return


(int)Session.LibraryUnloadOption.Immediately; }
}

Explanation:
using System;
using NXOpen;

The above piece of code represent s the import of System and NXOpen references. This is a
mandatory step to connect Journal with NX.

Session theSession = Session.GetSession();


FileNew fileNew1;
fileNew1 = theSession.Parts.FileNew();
fileNew1.TemplateFileName = "Blank";
fileNew1.Application = FileNewApplication.Gateway;
fileNew1.Units = NXOpen.Part.Units.Millimeters;
fileNew1.NewFileName = @"C:\temp\test.prt";
fileNew1.UseBlankTemplate = true;
fileNew1.MakeDisplayedPart = true;
NXObject nXObject1 = fileNew1.Commit();
fileNew1.Destroy();

FileNew i s an object used for creating parts . There are several methods within this object such
as template, unit s , file name, etc. These methods are specifically assigned values as per need.

NXOpen.Drawings.DrawingSheet nullDrawings_DrawingSheet = null;


NXOpen.Drawings.DrawingSheetBuilder drawingSheetBuilder1;
drawingSheetBuilder1 =
workPart.DrawingSheets.DrawingSheetBuilder(nullDrawings_DrawingSheet);
drawingSheetBuilder1.Option =
NXOpen.Drawings.DrawingSheetBuilder.SheetOption.StandardSize;
drawingSheetBuilder1.Units =
NXOpen.Drawings.DrawingSheetBuilder.SheetUnits.Metric;
drawingSheetBuilder1.StandardMetricScale =
NXOpen.Drawings.DrawingSheetBuilder.SheetStandardMetricScale.S11;
drawingSheetBuilder1.Height = 210.0;
drawingSheetBuilder1.Length = 297.0;
drawingSheetBuilder1.ProjectionAngle =
NXOpen.Drawings.DrawingSheetBuilder.SheetProjectionAngle.First;

There are several object builders available to use. These builders are used to creating something
in NX. Here DrawingSheetBuilder i s creating new drawing sheets with given specifications .
Several methods within the builder are used to do so. Based on which builder i s being used,
there are certain methods declared specifically to make it run successfully.
1/8: Create Blank Part With Drawing Sheet
Watch on YouTube - 1/8: Create Blank Part With Drawing Sheet | NX Open Programming |…

#2

UPDATE ALL SOLID EDGE COMPONENTS (Visual


Basic .Net)
Purpose:
When opening a Solid Edge assembly there is an incompatibility between loading construction
geometry and loading assembly-level features.

If the loading of assembly-level features is turned on then construction geometry within


component parts is never loaded, even if the option is checked in Solid Edge preferences.

The workaround interactively is to edit the component properties and run "File -> Properties - >
Interoperability -> Update from file "

The Journal does the job, traverses all components, and counts the bodies.

Then it updates each component part and counts the bodies again.

In case the number of bodies changes, it will report that component name in the listing window.

How to use:
Copy the entire code from the below page and paste it into the Journal editor to run.

In this example, the Visual Basic .NET programming language is used.

To change the Journal language, go to Menu, Preferences, and User Interface.


Source Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies

Module update_all_solid_edge_components

Dim s As Session = Session.GetSession()


Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = s.ListingWindow

Sub Main()
lw.Open()
Dim root As Component = _
s.Parts.Display.ComponentAssembly.RootComponent
If Not root Is Nothing Then
lw.WriteLine(root.DisplayName())
reportChildrensBodyStatus(root, 1)
Else
lw.WriteLine("The displayed part is not an assembly.")
End If

End Sub

Sub reportChildrensBodyStatus(ByVal comp As Component, ByVal indent


As Integer)

Dim space As String = Nothing


For ii As Integer = 1 To indent
space = space & " "
Next

For Each child As Component In comp.GetChildren()


Try
Dim cPart As Part = child.Prototype
Dim num_bodies_before = cPart.Bodies.ToArray().Length

ufs.Modl.EditImportBodyFeature(cPart.Tag, _
UFModl.ImportBodyFeatureEditOption.ImportBodyFeatureUpdateLink, _
nothing)

Dim num_bodies_after = cPart.Bodies.ToArray().Length

If num_bodies_before <> num_bodies_after Then


Dim num_bodies_loaded = num_bodies_after -

num_bodies_before

lw.WriteLine(space & child.DisplayName() & _


" was updated with " & _

num_bodies_loaded.ToString() & " bodies.")

End If
Catch ex As Exception
lw.WriteLine("Error: " & ex.Message)
End Try

reportChildrensBodyStatus(child, indent + 1)
Next
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer


Return Session.LibraryUnloadOption.Immediately
End Function

End Module

Explanation:
Imports NXOpen.UF
Imports NXOpen.Assemblies

Along with the import of System and NXOpen references , UF and Assemblies references are
imported, because API interfaces within these namespaces are used in this code.

Sub Main()
lw.Open()
Dim root As Component = _
s.Parts.Display.ComponentAssembly.RootComponent
If Not root Is Nothing Then
lw.WriteLine(root.DisplayName())
reportChildrensBodyStatus(root, 1)
Else
lw.WriteLine("The displayed part is not an assembly.")
End If
End Sub

RootComponent i s a property corresponding to Assemblies .ComponentAssembly, Returns the


top- level component, i.e. the component at the root of the component tree.
Sub reportChildrensBodyStatus(ByVal comp As Component, ByVal indent
As Integer)
Dim space As String = Nothing
For ii As Integer = 1 To indent
space = space & " "
Next
For Each child As Component In comp.GetChildren()
Try
Dim cPart As Part = child.Prototype
Dim num_bodies_before = cPart.Bodies.ToArray().Length
ufs.Modl.EditImportBodyFeature(cPart.Tag, _
UFModl.ImportBodyFeatureEditOption.ImportBodyFeatureUpdateLink, _
nothing)
Dim num_bodies_after = cPart.Bodies.ToArray().Length
If num_bodies_before <> num_bodies_after Then
Dim num_bodies_loaded = num_bodies_after -
num_bodies_before
lw.WriteLine(space & child.DisplayName() & _
" was updated with " & _
num_bodies_loaded.ToString() & " bodies.")
End If
Catch ex As Exception
lw.WriteLine("Error: " & ex.Message)
End Try
reportChildrensBodyStatus(child, indent + 1)
Next
End Sub

'For Each' loop t raver ses each child component from the assembly one by one, and counts the
bodies . Then it updates each component part using 'ufs.Modl.EditImpotBodyFeature' and
counts the bodies again. In case the number of bodies changes , it will report that component
name in the listing window.
2/8: Update All SolidEdge Components
Watch on YouTube - 2/8: Update All Solid Edge Components | NX Open Programming | P…

#3

REPORT TOP LEVEL PARTS IN SESSION (Visual


Basic .Net)

Purpose:
From a given assembly, this Journal reports only top-level parts in the session.

How to use:
You must have an assembly active in the NX session to run this Journal.

Source Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities

Module report_top_level_parts_in_session

Dim theSession As Session = Session.GetSession()


Dim ufs As UFSession = UFSession.GetUFSession()

Sub Main()

For Each thisPart As Part In theSession.Parts.ToArray()


Dim occs() As Tag

ufs.Assem.AskOccsOfPart(NXOpen.Tag.Null, thisPart.Tag, occs)

If occs.GetUpperBound(0) < 0 Then


'this part has no parent, so announce it
Echo("TOP Part: " & thisPart.FullPath())
End If

Next
End Sub

Sub Echo(ByVal output As String)


theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer


Return Session.LibraryUnloadOption.Immediately
End Function

End Module

Explanation:
For Each thisPart As Part In theSession.Parts.ToArray()
Dim occs() As Tag
ufs.Assem.AskOccsOfPart(NXOpen.Tag.Null, thisPart.Tag, occs)
If occs.GetUpperBound(0) < 0 Then
'this part has no parent, so announce it
Echo("TOP Part: " & thisPart.FullPath())
End If
Next

'For Each' loop traverses through all parts in an assembly. 'AskOccsOfPar t' Asks for tags of all
occurrences of "part" under the assembly of "parent_par t." If there i s no parent then that part is
displayed.
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function

Journal starts with an active NX session, specifying 'LibraryUnloadOption' describes when an


automation library should be unloaded from a running session. You shall find the library unload
option in every Journal at the end of the code. This is best practice to follow.

3/8: Report Top Level Parts in Session


Watch on YouTube - 3/8: Report Top Level Parts in Session | NX Open Programming | Par…
#4

REPORT ALL CUSTOM SYMBOLS (Visual Basic


.Net)
Purpose:
Using the new class 'DraftingCustomSymbolBuilder' to display the Master Symbol Name and
Path.

How to use:
Use a drawing with custom symbols present in it. Run Journal when the drawing is active in the
NX session.

Source Code:
Imports System
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.UF
Module report_all_custom_symbols
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = s.ListingWindow
Dim wp As Part = s.Parts.Work
Sub Main()
Dim symbol As NXOpen.Tag
lw.Open()
Dim custSymCol As CustomSymbolCollection =

s.Parts.Work.Annotations().CustomSymbols()

For Each cs1 as CustomSymbol in custSymCol


lw.WriteLine(vbCrLf + "Symbol: " & cs1.ToString())
lw.WriteLine(" Symbol Name: " + cs1.SymbolName)
lw.WriteLine(" Custom Name: " + cs1.Name)
Dim csBuilder1 As DraftingCustomSymbolBuilder =
wp.Annotations.CustomSymbols.CreateDraftingCustomSymbolBuilder(cs1)

lw.WriteLine(" MasterSymbolName: " + csBuilder1.MasterSymbolName)


lw.WriteLine(" MasterSymbolPath: " + csBuilder1.MasterSymbolPath)
csBuilder1.Destroy()
Dim vw_status As Integer
Dim vw_name As string
ufs.View.AskViewDependentStatus(cs1.Tag, vw_status, vw_name)
lw.WriteLine(" View Dependent: " + vw_status.ToString())
lw.WriteLine(" View: " + vw_name)
Dim csData1 As Annotations.CustomSymbolData = cs1.GetSymbolData()
Dim scale1 As double = csData1.Scale
Dim angle1 As double = csData1.Angle
Dim origin1 As Point3d = cs1.AnnotationOrigin
lw.WriteLine(" AnnotationOrigin: " & origin1.ToString())
lw.WriteLine(" Angle: " & angle1.ToString())
lw.WriteLine(" Scale: " & scale1.ToString())
Dim textdata1() As Annotations.CustomSymbolTextData
textdata1 = csData1.GetTextData()
For Each td As Annotations.CustomSymbolTextData in textdata1
lw.WriteLine(" text type: " & [Enum].GetName(GetType(TextType),

td.TextType))

Dim text() As String


text = td.GetText()
For Each t As String In text
lw.WriteLine(" text: " & t)
Next
Next
cs1.UpdateSymbolGeometry(origin1, scale1, angle1)
csData1.SetTextData(textdata1)
Next

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer


GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
End Function

End Module
Explanation:
CustomSymbolCollection class represents a collection of custom symbol objects . Methods
within 'Cus toSymbol' returns information for e.g. symbol name. 'CustomSymbolData' class
contains methods for fetching details like scale, angle, position, etc. of the symbol.
'CustomSymbolTextData' represents custom symbol text data. There are 2 level loops used in
the above example. The f i r s t loop works on theCus tom symbol object, the second loop works
on the text data of the custom symbol object.

4/8: Report All Custom Symbols From Drawing


Watch on YouTube - 4/8: Report All Custom Symbols From Drawing | Nx Open Programm…

Extras
What is CAD API | Application Programming Interface |
Computer Aided Design
Watch on YouTube - https://youtu.be/BFpfOie8eoQ

#5

UPDATE ALL DRAFTING VIEWS (Visual Basic .Net)


Purpose:
Update all 'out of date' drafting views in one go, even if there are several drawings sheets.

How to use:
Use a drawing with several views which need an update.

Source Code:
Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.Drawings
Imports NXOpen.UI
Imports NXOpen.Utilities

Module update_all_out_of_date_drafting_views_explicitly

Dim s As Session = Session.GetSession()

Sub Main()
For Each dwg As DrawingSheet In s.Parts.Display.DrawingSheets
If dwg.IsOutOfDate Then
For Each dv As DraftingView In dwg.GetDraftingViews()
If dv.IsOutOfDate Then
dv.Update()
End If
Next
End If

Next

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

Return Session.LibraryUnloadOption.Immediately

End Function

End Module

Explanation:
Loop ensures that every drawing sheet in a drawing document i s covered. ' IsOutOfDate' is a
simple handy method to check the status whether this Drawings.DrawingSheet is out of date.
And i f found out of date, then another loop picks each drawing view and updates it.

5/8: Update All Out Of Date Drafting Views


Watch on YouTube - 5/8: Update All Out of Date Drafting Views Explicitly | NX Open Progr…
Extras

What is the Difference Between CAD Developer and


Design Automation Engineer?
Watch on YouTube - https://youtu.be/EekAYDuQf-s

#6

EXPORT EXPRESSIONS FROM WORK PART (Visual


Basic .Net)
Purpose:
Export all expressions from a file to an external file.
How to use:
Use this Journal on a file that has at least one expression present.

Source Code:
Option Strict Off
Imports NXOpen
Imports System
Imports System.IO
Imports System.Environment
Imports System.Windows.Forms

Module export_expressions_from_work_part

Dim theSession As Session = Session.GetSession()


Dim workPart As Part = theSession.Parts.Work

Sub Main()

Dim filename As String = ""

If (save_file(filename) <> DialogResult.OK) Then


Echo("Input canceled...exit")
Else

workPart.Expressions.ExportToFile(ExpressionCollection.ExportMode.WorkPa
rt, _

filename, _
ExpressionCollection.SortType.AlphaNum)

End If

End Sub

Public Function save_file(ByRef filename) As DialogResult

Dim SaveExpFileDlg As SaveFileDialog = New SaveFileDialog()


Dim result As DialogResult
SaveExpFileDlg.Title = "Export Expressions File"
SaveExpFileDlg.AddExtension = True
SaveExpFileDlg.Filter = "Expression Data Files (*.exp)| *.exp"
SaveExpFileDlg.FilterIndex = 1
SaveExpFileDlg.InitialDirectory = "c:\users\"

result = SaveExpFileDlg.ShowDialog()
filename = SaveExpFileDlg.FileName
SaveExpFileDlg.Dispose()

Return result

End Function

Sub Echo(ByVal output As String)


theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function

End Module

Explanation:
'ExportToFile' method exports the expressions to a text file, or if 'file_name' is a null reference
(Nothing in Visual Basic), list the expressions in the listing window. save_file function checks if
an expression file with the same filename exists at a given location.
6/8: Export Expressions File
Watch on YouTube - 6/8: Export Expressions File | Parametric Krish | NX Open Programm…

Extras

Stages of Learning CAD Automation / CAD


Customization
Watch on YouTube - https://youtu.be/H_r8iJ_CLgk

#7

CLEAN UP WORK PART (Visual Basic .Net)


Purpose:
Clean up means eliminating certain inaccessible objects from the part file, like;

● delete unused expressions


● delete unused objects
● turn off highlighting
● clean up feature data
● clean up drafting objects
● delete unused fonts
● and some more.

This shall certainly improve performance in NX.

How to use:
Run this Journal on any given file.

Source code:
Option Strict Off
Imports System
Imports NXOpen

Module cleanup_work_part

Dim s As Session = Session.GetSession()

Sub Main()

Dim workPart As Part = s.Parts.Work

Dim partCleanup1 As PartCleanup

partCleanup1 = s.NewPartCleanup()
partCleanup1.TurnOffHighlighting = True
partCleanup1.DeleteUnusedObjects = True
partCleanup1.DeleteUnusedExpressions = True
partCleanup1.CleanupDraftingObjects = True
partCleanup1.CleanupFeatureData = True
partCleanup1.FixOffplaneSketchCurves = True
partCleanup1.CleanupMatingData = True
partCleanup1.DeleteUnusedFonts = True
partCleanup1.CleanupCAMObjects = True
partCleanup1.DoCleanup()
partCleanup1.Dispose()
Echo("Finished!")

End Sub

Sub Echo(ByVal output As String)


s.ListingWindow.Open()
s.ListingWindow.WriteLine(output)
s.LogFile.WriteLine(output)
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

Return Session.LibraryUnloadOption.Immediately

End Function

End Module

Explanation:

'PartCleanup' class has members which can be used to perform clean up. Above code performs
clean up activities like;

● delete unused expressions


● delete unused objects
● turn off highlighting
● clean up feature data
● clean up drafting objects
● delete unused fonts
● clean up mating data
● cleanup CAM objects
● fix off plane sketch curves
7/8: Clean Up Workpart
Watch on YouTube - 7/8: Clean Up work part Made with Clipchamp

#8

SHOW ALL FEATURE DIMENSIONS (Visual Basic


.Net)
Purpose:
Show all feature dimensions of the selected feature.

How to use:
Run this Journal on any given file.

Source code:
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.Features

Module show_all_feature_dimensions_of_selected_features

Sub Main()

Dim s As Session = Session.GetSession()


Dim ufs As UFSession = UFSession.GetUFSession()
Dim dp As Part = s.Parts.Display
Dim selectedFeatures() As Features.Feature =

selectFeatures("Select the features to show feature dimensions")

For ii As Integer = 0 To SelectedFeatures.Length - 1

selectedFeatures(ii).ShowDimensions()

Next

End Sub

Function selectFeatures(ByVal prompt As String) As Features.Feature()

Dim theUI As UI = UI.GetUI


selectFeatures = Nothing

theUI.SelectionManager.SelectFeatures(prompt,
Selection.SelectionFeatureType.Browsable, selectFeatures)

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY

End Function

End Module

Explanation:
FeatureCollection Class represents a collection of features .
In order to retrieve selected objects from Journal code, the UI classes used. This call contains
various elements that represent the NX User Interface. SelectionManager property i s used for
the current session of NX.

8/8: Show All Feature Dimensions of Selected Feature


Watch on YouTube - 8/8: Show All Feature Dimensions of Selected Feature | Nx Open Pro…

CONCLUSION
NXOpen is vast in nature and a Programming and customization tool with powerful features. It
is deep indeed.

NXOpen can be learned or rather started without a guide but it has limitations. One cannot be
good at learning on their own.

NXOpen is not straightforward to learn because of its complex nature. Reason number one is
understanding of the NXOpen Object hierarchy. Reason number two is the use of namespaces
from UF, SNAP, etc. makes it more confusing for beginners.

One shall know interactive NX in detail to start programming it. If you don 't know the features
and functions of NX, how can you automate them?

NXOpen comprises both knowledge of programming language and knowledge of NXOpen


programming interfaces. Lack of one of two cannot make you an NXOpen Engineer.
Ranging from simple customization utilities to advanced programming toolkits, the NX Open suite
of products provides an extensive and flexible environment for automating and customizing NX.
Apart from NXOpen, NX offers other programming tools like SNAP, GRID, Knowledge Fusion,
Manuscript, Block-UI Styler.

YOU ARE EITHER THE ONE THAT


CREATES AUTOMATION, OR YOU ARE
GETTING AUTOMATED.
-Tom Preston Warner
Attend the NXOpen Programming Masterclass
Free for a limited time, Register here!
Stay Connected

You might also like