Showing results for 
Search instead for 
Do you mean 
Reply

DLL Loads from only from StartUp Folder

Hi,

 

I have written a sample program, and placed the men file in Startup directory and dll in application directory. My Menu callbacks works only when i place the dll's in startup directory.

 

My folder structure

<UGINSTALL_DIR>/CustomApps/startup

<UGINSTALL_DIR>/CustomApps/application

 

Environment variable set

UGII_USER_DIR = %UGINSTALL_DIR%/CustomApps

 

Below is the men File data

 

VERSION 120 
EDIT UG_GATEWAY_MAIN_MENUBAR 

MENU SAMPLE
    BUTTON LOGIN 
    LABEL LOGIN 
    ACTIONS login 
END_OF_MENU 
TOP_MENU 
    CASCADE_BUTTON SAMPLE
    LABEL SAMPLE MENU 
END_OF_TOP_MENU

 

 

Below is the code 

using System;
using System.Collections.Generic;
using System.Text;
using NXOpen;
using NXOpen.UF;
using NXOpenUI;

namespace GetNXSession
{
    public class SampleNXSession
    {
        public static bool isDisposeCalled;
        //public static int Main(string[] args)
        public static int Startup()
        {
            int retValue = 0;
            try
            {
                NXOpen.Session thisSession = Session.GetSession();
                UI theUI = NXOpen.UI.GetUI();
                
                theUI.MenuBarManager.AddMenuAction("login", new NXOpen.MenuBar.MenuBarManager.ActionCallback(SampleNXSession.login));
            }
            catch (NXOpen.NXException ex)
            {
                // ---- Enter your exception handling code here -----
                // NX5
                UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
                // for NX4 use this
                // lw.Open(); lw.WriteLine(ex.Message);

            }
            return retValue;
        }

        public static NXOpen.MenuBar.MenuBarManager.CallbackStatus login(NXOpen.MenuBar.MenuButtonEvent buttonEvent)
        {
            UI.GetUI().NXMessageBox.Show("LOGIN", NXMessageBox.DialogType.Information, "LogIn Clicked");
            return NXOpen.MenuBar.MenuBarManager.CallbackStatus.Continue;
        }
        
        public static int GetUnloadOption(string arg)
        {
            //Unloads the image explicitly, via an unload dialog
            //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);

            //Unloads the image immediately after execution within NX
            return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);

            //Unloads the image when the NX session terminates
            // return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
        }

        public void Dispose()
        {
            try
            {
                if (isDisposeCalled == false)
                {
                    //TODO: Add your application code here 
                }
                isDisposeCalled = true;
            }
            catch (NXOpen.NXException ex)
            {
                // ---- Enter your exception handling code here -----

            }
        }
    }
}

 

Regards,
Santosh
9 REPLIES

Re: DLL Loads from only from StartUp Folder

On startup, NX only executes the .dll's in the startup folder. If the application is not in the startup folder, NX does not run it on startup to register the callback.

 

If you want the callback registered at startup, the .dll must be in the startup folder.

Re: DLL Loads from only from StartUp Folder

[ Edited ]

Then what is the use of application folder ?

 

Regards,
Santosh

Re: DLL Loads from only from StartUp Folder

Santosh,

 

The "application" folder is widely used for programs that do not need to load at startup.  Yours obviously needs to run at startup, so it needs to be in the "startup" folder.

 

By the way, any time you register a callback, you should change your unload option to something other than "immediately", so the callbacks that you register remain loaded and available.

 

Regards,

 

Steve

 

Re: DLL Loads from only from StartUp Folder

The application folder is for files that you do not want/need to load at startup. If you have a simple application that you want to run periodically or does not require callbacks to be registered at startup, you can put it in the application folder.

 

To execute a .dll in that folder, you would have to change the target of the ACTION item in your menu file to be the full path of the .dll.

 

 

Re: DLL Loads from only from StartUp Folder

[ Edited ]

So basically when my application needs to load during startup i need my dll
to be on the startup folder else I should have them on the application
folder.

One more clarification. Now I have only a single button which needs to be
registered during the startup. If I have many buttons which needs to be
loaded during startup will it not be a performance hit during NX
application startup?

I ll keep in mind about the unload.

Regards,
Santosh

(Sent from OnePlusOne-Cyanogen)

Regards,
Santosh

Re: DLL Loads from only from StartUp Folder

I have never had a need to register a menu callback, since all my custom applications are launched only on demand.

 

Depending on the type of application, you will mostly not need a registered callback.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: DLL Loads from only from StartUp Folder

[ Edited ]

Can you give an code/men file/folder structure example plz

Regards,
Santosh


(Sent from OnePlusOne-Cyanogen)

Regards,
Santosh

Re: DLL Loads from only from StartUp Folder

A menu entry looks like this:

BUTTON      JH_FBM_MARK_TILTED_HOLES
LABEL       Mark Tilted Holes
MESSAGE     Marks tilted holes with an asterisk and a vector
BITMAP      CamMarkTiltedHoles.bmp
ACTIONS     ${UGII_INITIAL_JOURNAL_DIR}\${UGII_VERSION}\CamMarkTiltedHoles.dll

The folder structure is the same as you use.

The image is placed inside of the folder called application.

 

The code is generated by the block UI styler, which I really recommend, since it makes live so much easier than tweaking WinForm dialogs.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: DLL Loads from only from StartUp Folder

[ Edited ]

OK. Thank you. I ll try that as well

Regards,
Santosh

(Sent from OnePlusOne-Cyanogen)

Regards,
Santosh