GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Foadsf/NXOpen_Python_tutorials: a collection of NXOpen Python tutorials

BranchesTags
Open more actions menu

Latest commit

 

History

16 Commits
16 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
Examples
Examples
 
 
Pictures
Pictures
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

NXOpen Python Tutorials

GitHub stars GitHub forks GitHub Sponsors License: CC0-1.0

A collection of NXOpen Python tutorials for automating Siemens NX CAD/CAM/CAE software.

Introduction

NXOpen is an Application Programming Interface (API) that gives users access to the Siemens NX/Simcenter 3D model and tool commands, allowing customization and extension of the baseline software capabilities. Applications include:

  • Creation and manipulation of part geometry and/or drawings
  • Data importing or parsing of model geometry information and analysis results
  • Automation of repetitive CAD/CAM/CAE tasks
  • Custom feature creation and batch processing

NXOpen can be used with multiple programming languages including C#, C++, Java, Python, and Visual Basic. This repository focuses on Python examples.

Getting Started

First Steps: Configuring NX for Python

To start with NX Python programming, you need to prepare your NX settings.

Step 1: Find or activate the Developer tab at the top NX ribbon:


Fig. 1 - Find or activate the Developer tab.

If the tab does not exist already, right-click on the top ribbon and find the Developer tab to activate it.

Step 2: Change the macro recording language from Visual Basic to Python.

One great way to develop or learn NX Python programming is to record macros while using the GUI. By default, NX saves macros in Visual Basic. To change that to Python, go to File > Preferences > User Interface:


Fig. 2 - Go to the User Interface Preference panel.

Or press Ctrl + 2 keyboard shortcut. Then in the User Interface Preferences dialog, change the Journal Language to Python:


Fig. 3 - Change the Journal Language to Python.

Tutorials

Example 1: Hello World! (Message Box)

Let's start with a very simple "Hello World!" example where a message window will show a text message.

# ex0001.py
import NXOpen.UF

def main(): 
    NXOpen.UF.UFSession.GetUFSession().Ui.DisplayMessage("Hello World!", 1)

if __name__ == '__main__':
    main()

Running the code:

Go to the Developer tab and find the Play button:


Fig. 4 - Find the Play button.

In the Journal Manager panel, click Browse to find and run the code:


Fig. 5 - The Journal Manager panel.

The result will be:


Fig. 6 - Message box window.

Example 2: Hello World! (Listing Window)

The message box window is good for alerting users of specific issues. However, the text is not searchable or selectable. Alternatively, we can use the Listing Window:

# ex0002.py
import NXOpen

def main(): 
    listing_window = NXOpen.Session.GetSession().ListingWindow
    
    listing_window.Open()
    listing_window.WriteFullline("Hello world!")
    listing_window.Close()

if __name__ == '__main__':
    main()

The result:


Fig. 7 - Information/Listing window.

Example 3: Creating a Cylinder Feature

This example demonstrates how to create 3D geometry programmatically using the CylinderBuilder:

# ex0003.py
import NXOpen
import NXOpen.Features

def cylinder_builder(session=NXOpen.Session.GetSession(), 
                     work_part=NXOpen.Session.GetSession().Parts.Work, 
                     height=100, 
                     diameter=50):
    mark_id = session.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Cylinder")
    cylinder = work_part.Features.CreateCylinderBuilder(NXOpen.Features.Feature.Null)
    cylinder.Diameter.SetFormula(str(diameter))
    cylinder.Height.SetFormula(str(height))
    nx_object = cylinder.Commit()
    return nx_object, mark_id

def main():
    cylinder_builder(height=40, diameter=100)

if __name__ == '__main__':
    main()

This creates a cylinder with the specified height and diameter that you can edit manually from the model history or update programmatically.

Repository Structure

NXOpen_Python_tutorials/
├── Examples/
│   ├── ex0001.py    # Message box "Hello World"
│   ├── ex0002.py    # Listing window output
│   └── ex0003.py    # Cylinder feature creation
├── Pictures/        # Screenshots for documentation
├── .gitignore
├── LICENSE          # CC0-1.0 Public Domain
└── README.md

Repository History

This repository was created in August 2021 and has evolved through contributions focused on educational content for NX automation.

gitGraph
   commit id: "init" tag: "v0.1"
   commit id: "gitignore"
   commit id: "license"
   commit id: "first-steps"
   commit id: "ex0001"
   commit id: "ex0002"
   commit id: "ex0003"
   commit id: "typo-fix"
   branch contributor
   checkout contributor
   commit id: "png-lowercase"
   commit id: "readme-paths"
   checkout main
   merge contributor id: "PR#3"
   commit id: "grammar-fixes" tag: "current"
Loading

Timeline

August 2021: Foundation

  • Initial commit with .gitignore and CC0 license
  • Added "First Steps" guide for NX Python setup
  • Created examples ex0001.py, ex0002.py, and ex0003.py
  • Fixed variable name typo (xn_object → nx_object)

January–February 2022: Standardization

  • File extension standardization (.PNG → .png) by contributor @j-eggi
  • README path updates for cross-platform compatibility
  • Merged Pull Request #3

September 2022: Polish

  • Grammar and capitalization fixes
  • Improved documentation clarity and formatting

Resources

Official Documentation

  • NXOpen Python Reference Guide (NX 10)
  • NXOpen Python Reference Guide (NX 11)
  • NXOpen Getting Started Guide
  • NXOpen Programmer's Guide

Community Resources

  • NX Journaling Forum - Community Q&A for NX automation
  • Siemens Community - Official Siemens support forums

Related Articles

  • What Is NX Open? (Explained with examples)
  • Automating Load Case Combination in Simcenter 3D using NXOpen + Python

Contributing

Contributions are welcome! If you have NXOpen Python examples you'd like to share:

  1. Fork this repository
  2. Create a new branch for your feature
  3. Add your example to the Examples/ folder
  4. Update the README with documentation
  5. Submit a Pull Request

Support This Project

If you find these tutorials helpful, please consider:

  • ⭐ Starring the repository
  • 🍴 Forking and contributing improvements
  • 💖 Sponsoring via GitHub Sponsors or Patreon

License

This work is dedicated to the public domain under CC0 1.0 Universal. You can copy, modify, distribute, and perform the work, even for commercial purposes, all without asking permission.

Author

Dr. Foad Sojoodi Farimani

  • GitHub: @Foadsf
  • Stack Overflow: Foad S. Farimani
  • Twitter: @fsfarimani
  • LinkedIn: fsfarimani

About

a collection of NXOpen Python tutorials

Resources

Readme
CC0-1.0 license
Activity

Stars

115 stars

Watchers

7 watching

Forks

15 forks
Report repository

Releases

Sponsor this project

Packages

Contributors

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.