切換應用模塊並且修改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; }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM