一、概述
在NX二次开发的学习中,浏览博客时发现看到[社恐猫]和[王牌飞行员_里海]这两篇博客中写道有关信息窗口内容的打印和将窗口内容保存为txt,个人人为在二次开发项目很有必要,因此做以下记录。
ListingWindow信息窗口发送信息四种位置类型
设置ListingWindow信息窗口发送信息的位置
二、显示类型
2.1信息只显示在ListingWindow信息窗口
关键代码:
cpp
UF_initialize();
//启动计时器
UF_timer_t timer = { 0 };
UF_begin_timer(&timer);
//创建块
UF_FEATURE_SIGN sign = UF_NULLSIGN;
double corner_pt[3] = { 0.0, 0.0, 0.0 };
char * edge_len[3] = { "100", "100", "100" };
tag_t blk_obj_id = NULL_TAG;
UF_MODL_create_block1(sign, corner_pt, edge_len, &blk_obj_id);
//结束计时器
UF_timer_values_t ValueTime = { 0 };
UF_end_timer(timer, &ValueTime);
//打印统计信息
std::ostringstream temp;
temp << "耗时:cpu time:" << ValueTime.cpu_time << "\n" << "耗时:real time:" << ValueTime.real_time<< "\n"<<"提示:保存信息窗口内容至:"<< "D:\\GetRunningTime.txt";
std::string tempStr = temp.str();
NXOpen::Session* theSession = NXOpen::Session::GetSession();
NXOpen::ListingWindow* list = theSession->ListingWindow();
list->SelectDevice(NXOpen::ListingWindow::DeviceType::DeviceTypeWindow,"");//默认类型可省略
if (!list->IsOpen()) list->Open();
list->WriteLine(tempStr.c_str());
list->Close();
UF_terminate();
2.2信息只保存在ListingWindow窗口D:\\GetRunningTime.txt
关键代码:
cpp
UF_initialize();
//启动计时器
UF_timer_t timer = { 0 };
UF_begin_timer(&timer);
//创建块
UF_FEATURE_SIGN sign = UF_NULLSIGN;
double corner_pt[3] = { 0.0, 0.0, 0.0 };
char * edge_len[3] = { "100", "100", "100" };
tag_t blk_obj_id = NULL_TAG;
UF_MODL_create_block1(sign, corner_pt, edge_len, &blk_obj_id);
//结束计时器
UF_timer_values_t ValueTime = { 0 };
UF_end_timer(timer, &ValueTime);
//打印统计信息
std::ostringstream temp;
temp << "耗时:cpu time:" << ValueTime.cpu_time << "\n" << "耗时:real time:" << ValueTime.real_time<< "\n"<<"提示:保存信息窗口内容至:"<< "D:\\GetRunningTime.txt";
std::string tempStr = temp.str();
NXOpen::Session* theSession = NXOpen::Session::GetSession();
NXOpen::ListingWindow* list = theSession->ListingWindow();
//信息只保存在ListingWindow窗口D:\\GetRunningTime.txt
list->SelectDevice(NXOpen::ListingWindow::DeviceType::DeviceTypeFile, "D:\\GetRunningTime.txt");
if (!list->IsOpen()) list->Open();
list->WriteLine(tempStr.c_str());
list->Close();
list->SelectDevice(NXOpen::ListingWindow::DeviceType::DeviceTypeWindow, "");
UF_terminate();
2.3信息显示在ListingWindow窗口并保存信息内容至D:\\GetRunningTime.txt
关键代码:
cpp
UF_initialize();
//启动计时器
UF_timer_t timer = { 0 };
UF_begin_timer(&timer);
//创建块
UF_FEATURE_SIGN sign = UF_NULLSIGN;
double corner_pt[3] = { 0.0, 0.0, 0.0 };
char * edge_len[3] = { "100", "100", "100" };
tag_t blk_obj_id = NULL_TAG;
UF_MODL_create_block1(sign, corner_pt, edge_len, &blk_obj_id);
//结束计时器
UF_timer_values_t ValueTime = { 0 };
UF_end_timer(timer, &ValueTime);
//打印统计信息
std::ostringstream temp;
temp << "耗时:cpu time:" << ValueTime.cpu_time << "\n" << "耗时:real time:" << ValueTime.real_time<< "\n"<<"提示:保存信息窗口内容至:"<< "D:\\GetRunningTime.txt";
std::string tempStr = temp.str();
NXOpen::Session* theSession = NXOpen::Session::GetSession();
NXOpen::ListingWindow* list = theSession->ListingWindow();
//信息显示在ListingWindow窗口并保存信息内容至D:\\GetRunningTime.txt
list->SelectDevice(NXOpen::ListingWindow::DeviceType::DeviceTypeFileAndWindow, "D:\\GetRunningTime.txt");
if (!list->IsOpen()) list->Open();
list->WriteLine(tempStr.c_str());
list->Close();
list->SelectDevice(NXOpen::ListingWindow::DeviceType::DeviceTypeWindow,"");
UF_terminate();
2.4DeviceType::DeviceTypeNone既不显示在ListingWindow窗口,也不保存信息至D:\\GetRunningTime.txt这里不进行说明。