一、概述
最近将唐工的教学视频基本上看完了,收获很大;昨天NX二次开发学习群中,有小伙伴说在从建模模块切换到加工模块是说有问题,我尝试了一下录制的代码,确实有BUG,调试了一下,找到了一种方法,做以下笔记,防止忘记。最近感觉学的内容有点多,不知怎么回事总是记忆不清。
二、切换模块函数的封装
/***************************************************************************************
**SwitchApplicationModules切换应用模块。
**1,没有模块;2,建模模块;3,外观造型设计;4、制图模块;5、加工模块;6、加工检测模块;
**7、加工生产线设计;8、运动仿真模块;9、PCB 设计-挠性印制电路设计;10,钣金模块
****************************************************************************************/
static string SwitchApplicationModules(const int &Value);
/*********************************************************************************************
**Function: SwitchApplicationModules切换应用模块
**FunctionType: int
**double Value 返回应用模块的标识
**tag_t BodyOrFaceTag 体或者面的TAG值
**SeeAlso UF_APP_NONE = 0; //没有应用模块
UG_APP_MODELING = 40; //建模模块Ctrl+M
UG_APP_STUDIO = 88; //外观造型设计 Ctrl+Alt+S
UG_APP_DRAFTING = 1; //制图模块Ctrl+Shift+D
UG_APP_MANUFACTURING = 16; //加工模块Ctrl+Alt+M
UG_APP_INSPECTION = 93; //加工检测模块Ctrl+Alt+I
APP_LINE_DESIGNER //加工生产线设计Ctrl+Shift+L
UG_APP_MECHANISMS = 14 //运动仿真模块Ctrl+Alt+K
UG_APP_FLEX_PCB = 92; //PCB 设计-挠性印制电路设计Ctrl+Alt+P
UG_APP_SBSM = 85; //钣金模块Ctrl+Shift+M
************************************************************************************************/
string LiangFuns::UserUFBaseFun::SwitchApplicationModules(const int &Value)
{
string SwitchApplication;
switch (Value)
{
case 1:
SwitchApplication = "UF_APP_NONE";
break;
case 2:
SwitchApplication = "UG_APP_MODELING";
break;
case 3:
SwitchApplication = "UG_APP_STUDIO";
break;
case 4:
SwitchApplication = "UG_APP_DRAFTING";
break;
case 5:
SwitchApplication = "UG_APP_MANUFACTURING";
break;
case 6:
SwitchApplication = "UG_APP_INSPECTION";
break;
case 7:
SwitchApplication = "APP_LINE_DESIGNER";
break;
case 8:
SwitchApplication = "UG_APP_MECHANISMS";
break;
case 9:
SwitchApplication = "UG_APP_FLEX_PCB";
break;
case 10:
SwitchApplication = "UG_APP_SBSM";
break;
}
return SwitchApplication;
}
三、运行代码
NXOpen::Session *theSession = NXOpen::Session::GetSession();
NXOpen::Part *workPart(theSession->Parts()->Work());
NXOpen::Part *displayPart(theSession->Parts()->Display());
// ----------------------------------------------
// Menu: 应用模块(N)->加工(C)->生产线设计(I)
// ----------------------------------------------
string ApplicationSwitch = UserUFBaseFun::SwitchApplicationModules(5);
NXString AppName = theSession->ApplicationName();
if (AppName.GetLocaleText() != ApplicationSwitch)
{
//theSession->ApplicationSwitchImmediate("UG_APP_MANUFACTURING");
theUI->MenuBarManager()->ApplicationSwitchRequest(ApplicationSwitch.c_str());
}
//记得加上头文件#include <NXOpen/MenuBar_MenuBarManager.hxx>
四、结果如下
标签:case,break,SwitchApplication,APP,NX,模块,二次开发,UG From: https://blog.csdn.net/weixin_47753171/article/details/137069136