NX Open is a powerful tool for automating NX CAD tasks. Below is source code that creates a new blank prt file with some predefined options. (first code block is in C sharp, and the other one is written in Visual Basic .Net)
Code in C Sharp
using System;
using NXOpen;
public class create_new_blank_part
{
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;
UI.GetUI().MenuBarManager.ApplicationSwitchRequest("UG_APP_MODELING");
}
public static int GetUnloadOption(string dummy)
{
return (int)Session.LibraryUnloadOption.Immediately;
}
}
Code in Visual Basic .NET
Imports System
Imports NXOpen
Module NXJournal
Sub Main (ByVal args() As String)
Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI()
Dim fileNew1 As FileNew
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
Dim nXObject1 As NXObject = fileNew1.Commit()
fileNew1.Destroy()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
UI.GetUI().MenuBarManager.ApplicationSwitchRequest("UG_APP_MODELING")
End Sub
End Module
The code creates a new blank part using Siemens NX CAD software through the NXOpen API. The program starts by importing the necessary libraries and defining a class named create_new_blank_part
. The Main
function initializes a new NX session using Session.GetSession()
. It then creates a new part using theSession.Parts.FileNew()
, sets the part template to “Blank”, sets the application to “Gateway”, sets the units to “Millimeters”, sets the file name and path, and finally commits the new part using fileNew1.Commit()
.
After committing the new part, the code sets workPart
and displayPart
to the active work part and the active display part respectively using theSession.Parts.Work
and theSession.Parts.Display
. Finally, the code switches the application to the modeling application using UI.GetUI().MenuBarManager.ApplicationSwitchRequest("UG_APP_MODELING")
.
The GetUnloadOption
function returns an integer value that specifies when the library should be unloaded. In this case, the value returned is Session.LibraryUnloadOption.Immediately
, which unloads the library as soon as it is no longer needed.
Learn CAD Automation using NX Open & Automate Design Tasks in Less Than 90 Days Without Any Prior Knowledge.
Attend the NX Open Masterclass to Discover
What’s Popular
Browse Popular, evergreen tutorials and how-to guides.
This journal get’s the name material used in part. Imports SystemImports NXOpenModule NXJournalSub Main (ByVal args() As String)Dim theSession As NXOpen.Session = …
This journal get’s the name material used in part. Imports SystemImports NXOpenModule NXJournalSub Main (ByVal args() As String)Dim theSession As NXOpen.Session = …
Datum Planes are a planar reference feature to help define other features, such as swept bodies and features at angles to the …
The use of computer-aided design (CAD) software has become an essential tool in engineering and manufacturing. There is no industry today that …
An attribute is a persistant way to store non-geometric data (i.e. not a point or curve or solid or feature). Attributes can …
An attribute is a persistant way to store non-geometric data (i.e. not a point or curve or solid or feature). Attributes can …
Design Engineers always spend more time on drawings for several reasons. A few of them are; Drawings are prime source of information …
It is quite possible to create a blank part and drawing sheet with one click of a button. Yes, you are right, …
NX Open is a powerful tool for automating NX CAD tasks. Below is source code that creates a new blank prt file …
As engineers and designers, we often have to work with complex 3D models and drawings, and extracting important information from these can …
NX Open is a powerful tool for working with imported geometries in NX.One common task that engineers and designers may need to …
https://youtu.be/5NWHlSM0sQ0 Q:Can you teach me nx open using visual basic .net? ChatGPT: Yes, I can help you get started with using Visual …