同事最近遇到了一个有趣的问题分享给我,想将点击对象属性信息后弹出的信息给保存到TXT文本中。我们一开始的方向是,这里面的信息肯定是ug自己写入的,想通过找内部函数,获取到写入这个信息的内部函数,但是找了很久也没搞出来是哪个。
后来在网上看见【王牌飞行员_里海】大佬的文章,思考后觉得通过改变信息窗口输出方式,直接可以达到我们的目的,尝试了一波,果然可以。感谢【王牌飞行员_里海】大佬的文章分享。以后有关类似的信息或者数据都可以尝试这种方法进行导出,个人认为简单好用。
参考文章:
UG\NX二次开发 信息窗口的4种输出方式 NXOpen::ListingWindow::DeviceType_ug2次开发输出消息框-CSDN博客
代码实测:
#include <NXOpen/UI.hxx>
#include <NXOpen/ListingWindow.hxx>
#include <NXOpen/NXMessageBox.hxx>
#include <NXOpen/Session.hxx>
#include <uf_defs.h>
#include <NXOpen/NXException.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/Face.hxx>
#include <NXOpen/Features_Brep.hxx>
#include <NXOpen/Features_FeatureCollection.hxx>
#include <NXOpen/Information.hxx>
#include <NXOpen/NXObject.hxx>
#include <NXOpen/ObjectGeneralPropertiesBuilder.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/SelectNXObjectList.hxx>
#include <NXOpen/Session.hxx>
extern DllExport void ufusr(char* param, int* returnCode, int rlen)
{
try
{
Session *theSession = Session::GetSession();
NXOpen::ListingWindow* list = theSession->ListingWindow();
//改变列表窗口输出方式为写入文件
list->SelectDevice(NXOpen::ListingWindow::DeviceType::DeviceTypeFile, "D:\\info_TEST.txt");
//打开列表窗口的流
list->Open();
//面属性信息(录制的,点击消息按钮后执行的nxope代码)
Part *workPart(theSession->Parts()->Work());
Part *displayPart(theSession->Parts()->Display());
SelectNXObjectList *selectNXObjectList1;
std::vector<NXObject *> selectedObjects1(1);
tag_t face_tag = 88888;
Face *face1(dynamic_cast<Face *>(NXObjectManager::Get(face_tag)));
selectedObjects1[0] = face1;
theSession->Information()->DisplayObjectsDetails(selectedObjects1);
//关闭列表窗口的流
list->Close();
//再次更改输出方式(写入信息窗口)可刷新缓冲区,释放txt文件
list->SelectDevice(NXOpen::ListingWindow::DeviceType::DeviceTypeWindow, "");
}
catch (exception& ex)
{
NXOpen::UI::GetUI()->NXMessageBox()->Show("", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
extern int ufusr_ask_unload(void)
{
return (UF_UNLOAD_IMMEDIATELY);
}
效果展示: