【UG\NX二次开发】NXOpen 将属性信息窗口导出TXT-信息窗口输出方式的运用

同事最近遇到了一个有趣的问题分享给我,想将点击对象属性信息后弹出的信息给保存到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);
}

效果展示:

  • 12
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

社恐猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值