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

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; }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值