切换应用模块并且修改UG标题栏文字

 1 using System;
 2 using NXOpen;
 3 
 4 public class NXJournal
 5 {
 6     [System.Runtime.InteropServices.DllImport("user32.DLL", EntryPoint = "SetWindowText")]
 7     public static extern int SetWindowText(IntPtr h, string str);
 8 
 9   public static void Main(string[] args)
10   {
11 
12     NXOpen.Session theSession = NXOpen.Session.GetSession();
13     NXOpen.Part workPart = theSession.Parts.Work;
14     NXOpen.Part displayPart = theSession.Parts.Display;
15 
16     //UG模块对应名称:
17     //加工: UG_APP_MANUFACTURING
18     //建模: UG_APP_MODELING
19     //基本环境: UG_APP_GATEWAY
20     //制图: UG_APP_DRAFTING
21     //没有打开部件: UG_APP_NOPART
22 
23     //查询当前模块
24     string AppName = theSession.ApplicationName;
25     //System.Windows.Forms.MessageBox.Show(AppName);
26 
27     try    
28     {
29         //从建模切换到加工 
30         if (AppName == "UG_APP_MODELING")
31         {
32             theSession.ApplicationSwitchImmediate("UG_APP_MANUFACTURING");
33         }
34 
35         //从加工切换到建模
36         else if (AppName == "UG_APP_MANUFACTURING")
37         {
38             theSession.ApplicationSwitchImmediate("UG_APP_MODELING");
39         }
40 
41         //其他模块默认切换到建模
42         else
43         {
44             theSession.ApplicationSwitchImmediate("UG_APP_MODELING");
45         }
46 
47         IntPtr ug = NXOpenUI.FormUtilities.GetDefaultParentWindowHandle();
48         SetWindowText(ug, "我的UG");
49         AppName = string.Empty;
50     }
51     catch(Exception e)
52     {
53         //throw表示把异常抛给UG处理
54         //屏蔽这一句,表示捕捉到的任何异常都不处理
55         //throw;
56     }
57 
58   }
59   public static int GetUnloadOption(string dummy) { return (int)NXOpen.Session.LibraryUnloadOption.Immediately; }
60 }

转自:切换应用模块并且修改UG标题栏文字 - 巫居树 - 博客园 (cnblogs.com)

posted @ 2021-09-27 16:41  KingMAX(没事杀杀毒)  阅读(550)  评论(0)    收藏  举报