NX二次开发-对象与句柄相互转换


#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;
}

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值