Subject: Sample NX Open .NET C# program : register callback action Note: GTAC provides programming examples for illustration only, and assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. GTAC support professionals can help explain the functionality of a particular procedure, but we will not modify these examples to provide added functionality or construct procedures to meet your specific needs. using System; using NXOpen; using NXOpen.UF; using NXOpen.Utilities; /* This program demonstrates adding a menuscript callback action to the File-> New option which will only allow the STANDARD action to happen when the program is being run in native mode. The corresponding menufile would look like this: VERSION 120 EDIT UG_GATEWAY_MAIN_MENUBAR MODIFY BUTTON UG_FILE_NEW ACTIONS/PRE this_callback END_OF_MODIFY Put the built class library (.dll/.sl/.so) and the above menufile (.men) file in a startup directory under any directory listed in either UGII_CUSTOM_DIRECTORY_FILE or UGII_UG_CUSTOM_DIRECTORY_FILE, E.G. UGII_USER_DIR. */ namespace GTACMenu { public class CMain { static NXOpen.UF.UFMb.CbStatus this_cb( IntPtr w, IntPtr client_data, IntPtr button) { UFSession ufs = UFSession.GetUFSession(); ufs.UF.PrintSyslog("\n@@@@@@@@@@@@@@@@@@@@@@@@@@\n", false); ufs.UF.PrintSyslog("Callback program is running\n", false); ufs.UF.PrintSyslog("@@@@@@@@@@@@@@@@@@@@@@@@@@\n", false); bool in_nxman; ufs.UF.IsUgmanagerActive(out in_nxman); if (in_nxman) return UFMb.CbStatus.CbCancel; else return UFMb.CbStatus.CbContinue; } public static int Startup() { UFSession ufs = UFSession.GetUFSession(); ufs.UF.PrintSyslog("\n@@@@@@@@@@@@@@@@@@@@@@@@@@\n", false); ufs.UF.PrintSyslog("Startup program is running\n", false); ufs.UF.PrintSyslog("@@@@@@@@@@@@@@@@@@@@@@@@@@\n", false); NXOpen.UF.UFMb.Action []uaActions = new NXOpen.UF.UFMb.Action[2]; uaActions[0].action_name = "this_callback"; uaActions[0].action_cb = new NXOpen.UF.UFMb.Cb(); uaActions[0].action_cb.cb = new UFMb.CallbackT(this_cb); uaActions[0].action_cb.cb_data = System.IntPtr.Zero; uaActions[1].action_name = null; uaActions[1].action_cb = new NXOpen.UF.UFMb.Cb(); uaActions[1].action_cb.cb = null; uaActions[1].action_cb.cb_data = System.IntPtr.Zero; ufs.Mb.AddActions(uaActions); return( 0 ); } public static int GetUnloadOption(string dummy) { return UFConstants.UF_UNLOAD_UG_TERMINATE; } } }