Intro To NXOpen For CAE
Intro To NXOpen For CAE
Intro To NXOpen For CAE
June, 2009
Introduction
NX Open is a collection of Application Programming Interface (API) toolkits that allow for the flexible integration of ancillary software applications with NX through an open architecture. The NX Open APIs, by design, provide an open architecture which can be utilized by third parties, customers , and in-house users for integrating and/or creating custom software applications. This workshop is intended as an introduction to using NX Journaling and Visual Basic to create a utility program that automates a CAE process, specifically, generating JT results files from a solver output file.
This workshop illustrates: 1. Creation of a NX Journal file 2. Creating a Visual Studio project using the NX Open Wizard 3. Using the journaled code in the Visual Studio project 4. Compiling the code into a NX batch executable 5. Running the executable 6. Adding custom user code to extend the journaled process Files provided: 1. PressFit.op2 2. Shiftboot.op2 3. Module1_Final.vb - Your code at the end of the workshop should look similar to this. Compare your code to it if you run into trouble.
Contents
Record a journal to capture the process Create a Visual Studio project and compile the journal into a batch executable Edit the code to make it a general tool Further enhancements
2.2.3.Select OK on the New FEM form 2.3. Import the solver results file 2.3.1.Open the Post Processing Navigator 2.3.2.Right click on the Imported Results line and select Import Results
2.3.3.Navigate to the folder containing PressFit.op2 and select it 2.3.4.Select OK on the Import Results form 2.4. Generate a Post Display 2.4.1.Open up the PressFit results item and generate a VonMises contour plot of element nodal stresses
2.5. Export a JT file of the post results 2.5.1.File, Export, JT 2.5.2.Navigate to the folder containing PressFit.op2 2.5.3.Name the JT file PressFit.jt 2.5.4.Select OK on the JT File form
The process above creates a journal file that will play back the exact steps that were recorded. It will only work for the specific parts used because filenames, options selections, etc. are hard coded 3. Verify that the journal plays back successfully 3.1. Close all parts in the NX Session (or exit NX completely and start a new session) 3.1.1.File, Close, All Parts 3.1.2.Select NO Close on the Close All Files dialog to close all files without saving 3.1.3.This should return you to a No Part Gateway session 3.2. Delete the PressFit.jt file 3.2.1.Open it in Teamcenter Visualization Pro to examine it first if youd like 3.2.2.Alternately, rename the above file to compare it to the one that will be generated when you replay the journal below 3.3. Replay the journal 3.3.1.Tools, Journal, Play (or Alt+F8 shortcut) 3.3.2.The writeJT.vb journal that was just recorded should be in the Recently Accessed Journals list. If so, double click it to run it. If not, use the Browse button to locate and run it 3.4. View the .jt file that was created when the Journal was re-run
4. Examine the journal file that was recorded 4.1. Double click on writeJT.vb to open it in Visual Studio 4.2. Note that each step of the process that was journaled is denoted by comments
' ---------------------------------------------' Dialog Begin New FEM ' ---------------------------------------------... ' ---------------------------------------------' Dialog Begin Import Results ' ---------------------------------------------...
4.3. Also note the following: 4.3.1.Filenames are hardcoded 4.3.2.Structures that represent NX Dialog options are defined 4.3.3.Undo marks are created.
Now that the structure of the application has been easily created through the journal recording, the application programmer can fine tune it to make a utility that is more general and reusable. The remainder of this workshop will do the following: 1. Create a Visual Studio project and compile the journal into a batch executable 2. Replace hard coded names with command line arguments 3. Loop through all load cases if they exist
Create a Visual Studio project and compile the journal into a batch executable
1. Create the Visual Studio project using the NX Open VB Wizard 1.1. Start Visual Studio 1.2. Select File, New Project 1.3. On the New Project form: 1.3.1.Select the NX6 Open VB Wizard 1.3.2.Set the name to writeJtBatch 1.3.3.Set the Location to somewhere appropriate on your machine 1.3.4.Uncheck the Create directory for solution box
1.3.5.Hit OK
1.4. Hit Next on the NX6 Open VB Wizard welcome form 1.5. On the Application Settings form: 1.5.1.Select An external application that runs independent of NX (EXE)
1.5.2.Hit Next 1.6. Hit Finish on the Entry Points form (leaving Explicit startup and unloading at session termination selected) You will now see a new solution containing a Module1.vb script and a ReadMe.txt file
2. Double click on Module1.vb. It contains an empty code framework based on the options selected in the wizard.
Option Strict Off Imports System Imports NXOpen Module Module1 ' Explicit Activation ' This entry point is used to activate the application explicitly Sub Main() Dim theSession As Session = Session.GetSession() ' TODO: Add your application code here End Sub End Module
3. Add code recorded in writeJT.vb to Module1.vb 3.1. Open writeJT.vb. Highlight all of the text in the Main subroutine (everything between Sub Main and End Sub) 3.2. Right click on the selected text and pick copy (or click on Edit in the menu bar and pick copy) 3.3. Close the writeJT.vb tab 3.4. Switch to the Module1.vb tab 3.5. Position the cursor below the TODO: Add your application code here comment 3.6. Right click and pick paste (or click on Edit in the menu bar and pick paste) There will be an error in the Visual Studio Error List window that states Local variable theSession is already declared in the current block. This is due to the fact that this line is in the Main subroutine in both the template code generated by the wizard and in the recorded journal. 4. Fix the error by deleting one of the two occurrences: 4.1. Double click on the error in the Error List. This will take you to the location of the second occurrence 4.2. Highlight the Dim theSession As line and hit delete If there is a warning about an invalid root namespace, you can ignore it. It will be resolved when you save the project, then exit and restart Visual Studio
5. Configure the project references 5.1. Double click on the My Project item in the Solution Explorer
5.2. Click on References in the vertical tab list on the left side
5.3. The four NXOpen references have Copy Local set to False. Change this to True 5.3.1. Shift-select the four NXOpen items in the References list 5.3.2.In the Properties pane, change Copy Local from False to True. This will copy the dlls from the NX installation into the folder that the executable is created in.
6. Build the executable 6.1. Build the executable by either: 6.1.1.Menus: 6.1.1.1. Select Build, Build writeJtBatch 6.1.2.Solution Explorer: 6.1.2.1. Right click on writeJtBatch and select Build 6.2. A writeJtBatch folder was created in the location specified in step 1.3.3 above. From that folder, you should have the following hierarchy: o bin Release 6.3. The Release folder should contain writeJtBatch.exe
7. Test the executable 7.1. Open up a NX enabled command window (cmd window with UGII_ROOT_DIR defined and included in PATH) 7.1.1.Start, All Programs, UGS NX6.0, NX Tools, Command Prompt 7.2. Change directory (cd) to the folder that contains PressFit.op2 7.3. Delete the PressFit.jt that was created during journal record 7.4. Run the executable by entering the full path to writeJtBatch.exe 7.5. The executable should run without errors and recreate the PressFit.jt file
2. Add a variable that derives the .jt output name from the input name 2.1. Enter the following just below the resultsFile line entered above. This code keeps everything to the left of the last dot (.) in the results filename and adds jt to the end of it. This should replace any results file extension (.op2, .unv, .fil, .rst) with .jt
Dim jtFile As String = Left(resultsFile, InStrRev(resultsFile, ".")) + "jt"
3. Add output messaging to give feedback to the user 3.1. Add the following two lines just below the previous two entered above
System.Console.WriteLine("Input results file: " + resultsFile) System.Console.WriteLine(" Output JT file: " + jtFile)
4. Replace the hardcoded filenames with the variables defined above 4.1. Scroll down (or search) through the code and find the line that the LoadImportedResult method is used. The function call takes three arguments, the second of which is the name of the results file. 4.1.1.Replace the quoted string in the second argument with the resultsFile variable
resultId1=theSession.Post.LoadImportedResult("PressFit", resultsFile, units1)
4.2. Now scroll down to one of the last lines of code where the PostviewExportDisplay method is used. The function call takes five arguments, the second of which is the name of the JT file. 4.2.1.Replace the quoted string in the second argument with the jtFile variable
theSession.Post.PostviewExportDisplay(1, jtFile, CAE.Post.Export.Jt, False, False)
5. Run the executable 5.1. Open a NX enabled command window 5.1.1.Run writeJtBatch.exe and specify the name (including full path) of the PressFit.op2 file as a command line argument. 5.1.2.Run writeJtBatch.exe again, this time specifying the full path to shiftboot.op2 as the input file 5.2. PressFit.jt and shiftboot.jt are both created
Further enhancements
The executable will now produce a JT file from any supported solver results file that contains stress data. Many more enhancements would need to be made to make this a distributable tool suitable for general use. Examples are: 1. Error checking/handling 1.1. Validating command line arguments 1.2. Ensuring that the specified results file exists 1.3. Ensuring that the directory that the JT file will be written to is writable 1.4. Etc. 2. Functionality 2.1. Options for producing different types of results plots 2.2. Options for scale factor of deformed plots 2.3. Specification of results file units and display units 2.4. Etc.