#include <NXOpen/Session.hxx>
#include <NXOpen/NXException.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/NXObjectManager.hxx>
#include <string.h>
#include <sstream>
#include <uf_defs.h>
#include <uf_ugmgr.h>
#include <uf.h>
#include <uf_modl.h>
#include <NXOpen/Features_BodyFeature.hxx>
#include <NXOpen/Face.hxx>
#undef CreateDialog
using namespace NXOpen;
void ufusr(char *parm, int *returnCode, int rlen)
{
UF_UGMGR_initialize(0, nullptr);
// 对象选择对话框
char chCue[] = "请选择实体!";
char chTitle[] = "选择实体";
int nScope = UF_UI_SEL_SCOPE_WORK_PART;
int nResponse = 0;
tag_t tObject = NULL_TAG;
double dCursor[3];
tag_t tView = NULL_TAG;
UF_UI_select_with_single_dialog(chCue, chTitle, nScope, NULL, NULL, &nResponse, &tObject, dCursor, &tView);
if (nResponse == UF_UI_OK nResponse == UF_UI_OBJECT_SELECTED nResponse == UF_UI_OBJECT_SELECTED_BY_NAME)
{
// 取消高亮
UF_DISP_set_highlight(tObject, 0);
// handle 转 tag
char* chHandle = UF_TAG_ask_handle_of_tag(tObject);
// handle 转 tag
tag_t tBody = UF_TAG_ask_tag_of_handle(chHandle);
NXMESSAGE << "实体: " << tBody << "\t句柄: " << chHandle << "\n" << endlPrint;
// 实体转特征
uf_list_p_t featList;
UF_MODL_ask_body_feats(tBody, &featList);
// 查询特征列表的数量
int nCount = 0;
UF_MODL_ask_list_count(featList, &nCount);
// 访问特征列表
tag_t tFeat = NULL_TAG;
UF_MODL_ask_list_item(featList, 0, &tFeat);
// 特征找实体特征
NXOpen::Features::BodyFeature * bodyfeat = dynamic_cast<NXOpen::Features::BodyFeature *>(NXOpen::NXObjectManager::Get(tFeat));
// 通过对象查询句柄并且打印
char chInfo[MAX_PATH] = { "\0" };
UF_UI_open_listing_window();
for (int i = 0; i < bodyfeat->GetFaces().size(); i++)
{
chHandle = UF_TAG_ask_handle_of_tag(bodyfeat->GetFaces()[i]->Tag());
sprintf_s(chInfo, "面:%d\t句柄:%s\n", bodyfeat->GetFaces()[i]->Tag(), chHandle);
UF_UI_write_listing_window(chInfo);
}
// 释放内存
UF_MODL_delete_list(&featList);
}
UF_UGMGR_terminate();
}
int ufusr_ask_unload()
{
return (int)Session::LibraryUnloadOptionImmediately;
}
NX二次开发-对象与句柄相互转换
最新推荐文章于 2024-07-22 09:38:37 发布