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; }
}