列文章目录
文章目录
前言
随着工业智能化的不断发展,UG二次开发的需求越来越多,也吸引了大批的二开从业人员,本人作为一名资深IT从业者(10年+)也毅然加入二次开发大军。
然而,和流行IT行业(互联网、金融、医疗等)相比,工业智能化的门槛显得更高一点,专业的工业软件,相对封闭的开发理念和更小的开发圈子,让刚进入二开的从业者有点举步维艰。边学边整理,希望通过这系列文章的整理能给二开的生态增添一叶绿。
一、UI样式文件分析
1. 样式文件目录
目录位置:UGOPEN\SampleNXOpenApplications\C++\BlockStyler\HoleCoordinates\HoleCoordinates.dlx
2. 样式文件导入预览
3. 样式文件解析
本实例主要用到了一下控件:指定点、指定矢量、面收集器、操作按钮、列表框
二、源码文件解析
1. 主程序分析
extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
{
try
{
theHoleCoordinates = new HoleCoordinates();
// The following method shows the dialog immediately
theHoleCoordinates->Show();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
HoleCoordinates::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
delete theHoleCoordinates;
}
HoleCoordinates::HoleCoordinates()
{
try
{
// Initialize the NX Open C++ API environment
HoleCoordinates::theSession = NXOpen::Session::GetSession();
HoleCoordinates::theUI = UI::GetUI();
theDialogName = "HoleCoordinates.dlx";
theDialog = HoleCoordinates::theUI->CreateDialog(theDialogName.c_str());
// Registration of callback functions
theDialog->AddApplyHandler(make_callback(this, &HoleCoordinates::apply_cb));
theDialog->AddUpdateHandler(make_callback(this, &HoleCoordinates::update_cb));
theDialog->AddInitializeHandler(make_callback(this, &HoleCoordinates::initialize_cb));
theDialog->AddDialogShownHandler(make_callback(this, &HoleCoordinates::dialogShown_cb));
}
catch(exception& ex)
{
std::string exceptionText = ex.what();
throw;
}
}
构造函数里,我们需要关注dlx文件加载,回调方法里面主要关注:提交方法apply_cb、更新方法update_cb、初始化方法initialize_cb。
2. 处理模块分析
2.1 初始化方法
void HoleCoordinates::initialize_cb()
{
try
{
workPart = HoleCoordinates::theSession->Parts()->Work();
displayPart = HoleCoordinates: