【NX二次开发】判断对象是否在装配中UF_ASSEM_is_occurrence()
如图左面的体是部件中的体,右面的体是当前显示部件下的体。我们选择体对象,使用UF_ASSEM_is_occurrence()函数判断体是否在装配中。下面是源码和演示。
源码:
#include <NXOpen/Session.hxx> #include <NXOpen/NXException.hxx> #include "me.hpp" int doWork(tag_t tagObj) { if (UF_ASSEM_is_occurrence(tagObj)) { uc1601("输入的是装配中的对象,即事例!", 1); } else { uc1601("输入的是当前显示部件下的对象,即原型!", 1); } return 0; } vector<tag_t> selectBodies() { vector<tag_t> bodies; double cursor[3] = { 0, 0, 0 }; int response, i, count; tag_t *objects; UF_UI_selection_options_t opts1; opts1.other_options = 0; opts1.reserved = NULL; opts1.num_mask_triples = 1; opts1.scope = UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY; UF_UI_mask_t mask_triples[] = { 70, 0, 0 }; opts1.mask_triples = mask_triples; UF_UI_lock_ug_access(UF_UI_FROM_CUSTOM); UF_UI_select_by_class("请选择体", &opts1, &response, &count, &objects); for (i = 0; i < count; i++) { UF_DISP_set_highlight(objects[i], 0); bodies.push_back(objects[i]); } UF_UI_unlock_ug_access(UF_UI_FROM_CUSTOM); return bodies; } extern DllExport void ufusr(char *param, int *returnCode, int rlen) { UF_initialize(); vector<tag_t> vecBodys = selectBodies(); for (int i = 0; i < vecBodys.size(); i++) { tag_t tagObj = vecBodys[i]; doWork(tagObj); } UF_terminate(); } extern int ufusr_ask_unload(void) { return (UF_UNLOAD_IMMEDIATELY); }
演示: