I am playing with a Graphical User Interface (GUI) (created with the NX UI buildder) and the macro crashes when trying to display the GUI. I am getting the error msg
Object reference not set to an instance of an object
and the lines of code "quoted" seem to point to the Public Shared Sub Main() in the Public Class MyGUI
Ani idea what is not being initialised?
I think we'll need more information about what you are doing in order to help. Can you post your code? Are you running from the Journal interface, or are you building a .DLL? What version of NX are you using?
NX9. Runing from Play > Journal
Code cannot be posted at the moment but will look at replicating the problem
This is the Sub where the problem appears to be
Public Shared Sub Main() Try theNXMacroGUI = New NXMacroGUI() ' The following method shows the dialog immediately theNXMacroGUI.Show() Catch ex As Exception '---- Enter your exception handling code here ----- theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString) Finally If theNXMacroGUI IsNot Nothing Then theNXMacroGUI.Dispose() End If End Try End Sub
Is NX able to find the dlx file?
See the NX syslog for the information if it finds it.
The dlx file must be placed in an application subfolder of UGII_SITE_DIR, UGII_GROUP_DIR, UGII_USER_DIR or a folder containd in custom_dirs.dat
Production: NX10.0.3, VERICUT 8.1, FBM, MRL 3.1.7 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 11.4
Development: C (ITK), .NET, Tcl/Tk Testing: NX12.0 | AWC 3.4 Preparing: NX12.0
Employees of the customers, together we are strong
How to Get the Most from Your Signature in the Community
NX Customization - Best Practice Guide
Thanks for the input Stephan.
I am not so sure about the importance of the .dlx file to be located in UGII_SITE_DIR, UGII_GROUP_DIR, UGII_USER_DIR or a folder containd in custom_dirs.dat
I have tested one of the provided example (CampbellCsvToAfu) and it works fine. ie the GUI is displayed. The function which seems to create the problem is "lifted" from this example
' 1) A copy of CampbellCsvToAfu.dlx must be in one of the following locations:
' 1.) In the same folder as CampbellCsvToAfu.vb
' 2.) From where NX session is launched
' 3.) $UGII_USER_DIR/application
' 4.) For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly
' recommended. This variable is set to a full directory path to a file
' containing a list of root directories for all custom applications.
' e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_ROOT_DIR\menus\custom_dirs.dat
' 2) Run this program from within a FEM or SIM file in NX Advanced Simulation
' - Use 'Tools > Journal > Play' to run CampbellCsvToAfu.vb
Where do I get the NX syslog file?
If you run the (uncompiled) journal as you get it from the BlockStyler (dlx file in the same dir as vb file) the journal won't find the dlx file because the (compiled) journal.dll is located somewhere in the users temp dir. So you have to put the dlx file to one of the other locations suggested by the documentation.
But: with the default BlockStyler generated code you would get an other error message in this case (something like ...dlx file not found).
the NX example provided (see previous comment) does not need a .dll to run (and works fine!). I did have the issue of ".dlx file not found" initally and after going thorugh the example I fixed it (as per the example) using the following code (I replaced "CampbellCsvToAfu" by my own name !)
theDialogName = IO.Path.ChangeExtension(theSession.ExecutingJournal, "dlx") If theDialogName = "" Then theDialogName = "CampbellCsvToAfu_BS.dlx" Else If Not IO.File.Exists(theDialogName) Then theDialogName = "CampbellCsvToAfu.dlx" End If End If
I don't have the example 'CampbellCsvToAfu' in my NX installation. So I have to guess...
As for compiled/uncompiled: NX compiles your vb code on-the-fly when you start a journal, puts the result (named journal.dll) in the users temp dir and runs this compiled dll. Getting the journals name and path by theSession.ExecutingJournal gets you around the dll location problem.
I don't understand why you need the IF...THEN..ELSE clause but if your journal has the same name and path as your dlx file there seems to be nothing wrong with this part of your code and the error must be somewhere else.