文章目录
- 1、前言
- 2、在UG NX中创建多个体对象
- 3、代码实现
- 4、运行结果
1、前言
在一个CAD模型中或者工作部件下,如何获得想要的体对象,首先要遍历模型中的体,然后根据体的名称或者体的属性获得。本文讲一下C++下的遍历体对象的二次开发实现
2、在UG NX中创建多个体对象
3、代码实现
我们编写遍历体\面\边的代码如下:
NXOpen::ListingWindow* lw1 = theSession->ListingWindow();
lw1->Open();
NXOpen::Part* workPart = theSession->Parts()->Work();
NXOpen::BodyCollection *bodyCollection = workPart->Bodies();
std::vector<NXOpen::Body*>bodyArray;
std::vector<NXOpen::Face*>faceArray;
std::vector<NXOpen::Edge*>edgeArray;
NXOpen::BodyCollection::iterator iter;
int i = 1;
for (iter = bodyCollection->begin();iter!=bodyCollection->end();iter++)
{
NXOpen::Body* body = *iter;
bodyArray.push_back(body);
//char* mes;
NXString nXString1 = std::to_string(i) + ":" +body->JournalIdentifier();
lw1->WriteLine(nXString1);
std::vector<NXOpen::Face*>faceArray1 = body->GetFaces();
std::vector<NXOpen::Face*>::iterator iter1;
for (iter1 = faceArray1.begin(); iter1 != faceArray1.end();iter1++)
{
NXOpen::Face* face = *iter1;
/* lw1->WriteLine(face->JournalIdentifier());*/
faceArray.push_back(face);
std::vector<NXOpen::Edge*>edgeArray1 = face->GetEdges();
std::vector<NXOpen::Edge*>::iterator iter2;
for (iter2 = edgeArray1.begin();iter2!=edgeArray1.end();iter2++)
{
edgeArray.push_back(*iter2);
NXOpen::Edge *edge = *iter2;
tag_t edgeTag = edge->Tag();
/* string str_str = "边" + std::to_string((int)edgeTag);
char* char_str = (char *)str_str.data();
lw1->WriteLine(char_str);*/
}
}
i++;
}
4、运行结果
通过输出信息,我们可以看出,遍历体的代码是正确有效的。