这个是UF_UI_ask_global_sel_object_list这个UFUN函数的NXOpen版本


NX9+VS2012

#include <uf_defs.h>
#include <NXOpen/NXException.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/UI.hxx>
#include <NXOpen/ListingWindow.hxx>
#include <NXOpen/NXMessageBox.hxx>
#include <NXOpen/NXObject.hxx>
using namespace NXOpen;


Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
Part *displayPart(theSession->Parts()->Display());
UI *theUI = UI::GetUI();

//返回当前选择的对象的数量
int index = theUI->SelectionManager()->GetNumSelectedObjects();

theSession->ListingWindow()->Open();
for (int i = 0; i < index; i++)
{
//返回选择列表上的第n个对象
NXObject *object = theUI->SelectionManager()->GetSelectedObject(i);

//打印tag
char msg[256];
sprintf(msg, "tag:%d",object->Tag());
theSession->ListingWindow()->WriteLine(msg);
}

阿飞
2021年9月4日


NX二次开发-NXOpen不用UI控件,鼠标选中对象获得tag theUI->SelectionManager()->GetSelectedObject(i);_二次开发

 

阿飞

2021年9月4日