C++
//用户头文件
#include <NXOpen/DisplayManager.hxx>
#include <NXOpen/Body.hxx>
#include <NXOpen/BodyCollection.hxx>
#include <NXOpen/NXException.hxx>
#include <NXOpen/NXObject.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/Builder.hxx>
#include <NXOpen/Features_FeatureCollection.hxx>
#include <NXOpen/SelectObjectList.hxx>
#include <NXOpen/NXObjectManager.hxx>
#include <NXOpen/SelectNXObjectList.hxx>
//用户代码
Part *workPart = theSession->Parts()->Work();
Part *displayPart = theSession->Parts()->Display();
std::vector<tag_t> BodyVecotor;
NXOpen::Body *workBody;
NXOpen::BodyCollection *Bodys = workPart->Bodies();
NXOpen::BodyCollection::iterator Ite = Bodys->begin();
//遍历
for (; Ite != Bodys->end(); ++Ite)
{
workBody = (*Ite);
BodyVecotor.push_back(workBody->Tag());
Body *body1(dynamic_cast<Body *>(NXObjectManager::Get(workBody->Tag())));
//Body *body1(dynamic_cast<NXOpen::Body *>(workPart->Bodies()->FindObject(workBody->JournalIdentifier())));
//Features::BodyFeature *bodyFeatObject(dynamic_cast<BodyFeature*> (feature1)); //特征转换body
//移除参数
Features::RemoveParametersBuilder *removeParametersBuilder1;
removeParametersBuilder1 = workPart->Features()->CreateRemoveParametersBuilder();
bool added1;
added1 = removeParametersBuilder1->Objects()->Add(body1);
NXObject *nXObject1;
nXObject1 = removeParametersBuilder1->Commit();
removeParametersBuilder1->Destroy();//释放
//改色
DisplayModification *displayModification1;
displayModification1 = theSession->DisplayManager()->NewDisplayModification();
displayModification1->SetApplyToAllFaces(false);
displayModification1->SetApplyToOwningParts(false);
displayModification1->SetNewWidth(DisplayableObject::ObjectWidthOne);
displayModification1->SetNewColor(1+BodyVecotor.size()*12); //设置色
displayModification1->SetNewTranslucency(40);//设置透明度
std::vector<NXOpen::DisplayableObject *> objects2(1);
objects2[0] = body1;
displayModification1->Apply(objects2);
delete displayModification1;
}
char msg[256];
sprintf_s(msg, "当前有%d个体", BodyVecotor.size());
//弹出消息框(四种消息框 错误:DialogTypeError 警告:DialogTypeWarning 提示:DialogTypeInformation 询问:DialogTypeQuestion
theUI->NXMessageBox()->Show("提示", NXOpen::NXMessageBox::DialogTypeWarning, msg); //弹出消息框提示