Create Blank Part With Drawing Sheet Using NX Open APIs | CAD Automation | C Sharp

It is quite possible to create a blank part and drawing sheet with one click of a button. Yes, you are right, this can be done with the journal. This journal below is written in C sharp programming language.

Exactly how you either select a pre-defined template or custom apply a few settings on top of the existing template, the same can be done with writing a code inside the journal.

For example, part units, here millimeters units is applied. Template file name blank, this means no pre-defined template is used.

In NX Open, objects like features, geometries, and even drawing sheets are created using builder objects. These are nothing but create functions, also called factory objects.

using System; 
using NXOpen;
public class blank_part_w_drawing_sheet
{
public static void Main(string[] args)
{
Session theSession = Session.GetSession();
FileNew objNewFile;
objNewFile = theSession.Parts.FileNew();
objNewFile.TemplateFileName = "Blank";
objNewFile.Application = FileNewApplication.Gateway;
objNewFile.Units = NXOpen.Part.Units.Millimeters;
objNewFile.NewFileName = @"C:\temp\test.prt";
objNewFile.UseBlankTemplate = true;
objNewFile.MakeDisplayedPart = true;
NXObject objNX1 = objNewFile.Commit();
objNewFile.Destroy();
Part workPart = theSession.Parts.Work;
Part displayPart = theSession.Parts.Display;
NXOpen.Drawings.DrawingSheet nullDrawings_DrawingSheet = null;
NXOpen.Drawings.DrawingSheetBuilder objDrawingSheetBuilder;
objDrawingSheetBuilder = workPart.DrawingSheets.DrawingSheetBuilder(nullDrawings_DrawingSheet);
objDrawingSheetBuilder.Option = NXOpen.Drawings.DrawingSheetBuilder.SheetOption.StandardSize;
objDrawingSheetBuilder.Units = NXOpen.Drawings.DrawingSheetBuilder.SheetUnits.Metric;
objDrawingSheetBuilder.StandardMetricScale = NXOpen.Drawings.DrawingSheetBuilder.SheetStandardMetricScale.S11;
objDrawingSheetBuilder.Height = 210.0;
objDrawingSheetBuilder.Length = 297.0;
objDrawingSheetBuilder.ProjectionAngle = NXOpen.Drawings.DrawingSheetBuilder.SheetProjectionAngle.First;
NXObject objNX2 = objDrawingSheetBuilder.Commit();
objDrawingSheetBuilder.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;
}
}




In this example, DrawingSheetBuilder is used to create a drawing sheet.

This builder is part of Drawings namespace. There are several things can be defined inside this builder, for example, sheet size (width and height), metric units, sheet scale, project angle (first angle method or third angle method).

ApplicationSwitchRequest which is UI function, can set the drafting application in newly created part.

You can simply copy the above code and get inside your NX CAD software to run it. You can even try doing small tweaks with little knowledge of C sharp programming.

 

Social Connect

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 …