using System; using NXOpen; public class NXJournal { [System.Runtime.InteropServices.DllImport("user32.DLL", EntryPoint = "SetWindowText")] public static extern int SetWindowText(IntPtr h, string str); public static void Main(string[] args) { NXOpen.Session theSession = NXOpen.Session.GetSession(); NXOpen.Part workPart = theSession.Parts.Work; NXOpen.Part displayPart = theSession.Parts.Display; //UG模塊對應名稱: //加工: UG_APP_MANUFACTURING //建模: UG_APP_MODELING //基本環境: UG_APP_GATEWAY //制圖: UG_APP_DRAFTING //沒有打開部件: UG_APP_NOPART //查詢當前模塊 string AppName = theSession.ApplicationName; //System.Windows.Forms.MessageBox.Show(AppName); try { //從建模切換到加工 if (AppName == "UG_APP_MODELING") { theSession.ApplicationSwitchImmediate("UG_APP_MANUFACTURING"); } //從加工切換到建模 else if (AppName == "UG_APP_MANUFACTURING") { theSession.ApplicationSwitchImmediate("UG_APP_MODELING"); } //其他模塊默認切換到建模 else { theSession.ApplicationSwitchImmediate("UG_APP_MODELING"); } IntPtr ug = NXOpenUI.FormUtilities.GetDefaultParentWindowHandle(); SetWindowText(ug, "我的UG"); AppName = string.Empty; } catch(Exception e) { //throw表示把異常拋給UG處理 //屏蔽這一句,表示捕捉到的任何異常都不處理 //throw; } } public static int GetUnloadOption(string dummy) { return (int)NXOpen.Session.LibraryUnloadOption.Immediately; } }
