NX二次开发 NXOpen部件操作
NX8.0+VS2010
#include <uf_defs.h>
#include <NXOpen/Session.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/ListingWindow.hxx>
using namespace NXOpen;
extern "C" DllExport int ufusr_ask_unload()
{
return (int)NXOpen::Session::LibraryUnloadOptionImmediately;
}
extern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)
{
//通过Session的静态函数得到NX Session实例对象
Session *theSession = NXOpen::Session::GetSession();
//通过Parts属性得到PartCollection集合对象
PartCollection *partList = theSession->Parts();
//通过iterator迭代器遍历所有Part
for (PartCollection::iterator itr = partList->begin(); itr != partList->end(); ++itr)
{
//转换
BasePart *processPart = *itr;
//打印Part的名字
theSession->ListingWindow()->Open();
theSession->ListingWindow()->WriteLine(processPart->Name());
}
}