首页 NXOpen C++ 对象遍历与查找

NXOpen C++ 对象遍历与查找

小白鼠 2019-03-29 08:15:52 0 3858
通用NX对象包含永久NX对象和临时NX对象。
常用的永久NX对象有部件Part、几何体Body、面Face、边Edge、特征Feature等。
————————————————
NXOpen 把tag分的更细了比如:
Part *part; //声明部件数组
NXOpen::Point*point1;  //声明点
Features::Feature*fcList; //声明特征数组
其它略
————————————————
NXOpen对象遍历与查找 都是通过“迭代的方法”比如 获得所有部件 和 获得所有特征 其它同理。

————————————————

//遍历所有部件

//遍历所有部件
//打印所有部件路径
#include <NXOpen/Session.hxx>                   //有关Session绘画头文件
#include <NXOpen/Part.hxx>                      //有关部件头文件
#include <NXOpen/PartCollection.hxx>            //有关部件头文件
#include <sstream>
#include <NXOpen/ListingWindow.hxx>

Session *theSession = Session::GetSession(); //获得Session绘画
theSession->ListingWindow()->Open();  //打开信息窗口
theSession->ListingWindow()->WriteLine("输出所有特征类型信息\n");
Part *part; //声明部件数组
PartCollection *partList =theSession->Parts();  //迭代
PartCollection::iterator itr=partList->begin(); //获得第一个部件
for (;itr!=partList->end();++itr)               //循环遍历所有部件
{
	part=(*itr);   //获得特征赋值给part
	theSession->ListingWindow()->WriteLine(part->FullPath());//打印获得的部件路径
	theSession->ListingWindow()->WriteLine("\n");
}   
循环遍历所有特征
//打印所有特征类型
#include <NXOpen/Session.hxx>                   //有关Session绘画头文件
#include <NXOpen/Part.hxx>                      //有关部件头文件
#include <NXOpen/PartCollection.hxx>            //有关部件头文件
#include <NXOpen/Features_Feature.hxx>          //有关特征头文件
#include <NXOpen/Features_CylinderBuilder.hxx>  //有关特征头文件
#include <NXOpen/Features_FeatureCollection.hxx>//有关特征头文件
#include <NXOpen/Features_FeatureBuilder.hxx>   //有关特征头文件
#include <sstream>
#include <NXOpen/ListingWindow.hxx>


Session *theSession = Session::GetSession(); //获得Session绘画
Part *workPart(theSession->Parts()->Work()); //获得工作部件

theSession->ListingWindow()->Open();  //打开信息窗口
theSession->ListingWindow()->WriteLine("输出所有特征类型信息\n");
Features::Feature*fcList;
Features::FeatureCollection *fc=workPart->Features();//迭代
Features::FeatureCollection::iterator itr=fc->begin();//获得第一个特征
for (;itr!=fc->end();++itr)        //循环获得所有特征
{
	fcList=(*itr); //获得特征赋值给fcList
	theSession->ListingWindow()->WriteLine(fcList->FeatureType()); //获得特征类型打印
	theSession->ListingWindow()->WriteLine("\n");
}
遍历 ·

发表评论