怡宁塑胶模具设计

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C++ 2010

#include <uf.h>
#include <uf_object_types.h>
#include <uf_obj.h>
#include <uf_modl.h>
#include <uf_assem.h>
#include <uf_kf.h>
#include <uf_ui.h>
#include <NXOpen/Body.hxx>
#include <NXOpen/BodyCollection.hxx>
#include <NXOpen/Line.hxx>
#include <NXOpen/LineCollection.hxx>
#include <NXOpen/Point.hxx>
#include <NXOpen/PointCollection.hxx>
#include <NXOpen/Arc.hxx>
#include <NXOpen/ArcCollection.hxx>
#include <NXOpen/Spline.hxx>
#include <NXOpen/SplineCollection.hxx>
#include <NXOpen/Features_RemoveParametersBuilder.hxx>
#include <NXOpen/NXObjectManager.hxx>
#include <NXOpen/Features_FeatureCollection.hxx>
#include <NXOpen/SelectNXObjectList.hxx>
#include <NXOpen/SelectObjectList.hxx>

 

 //用户代码
 Features::Feature* thefeature;
 Features::FeatureCollection *features=workPart->Features();//迭代
 Features::FeatureCollection::iterator itr=features->begin();//获得第一个特征
 std::vector<tag_t> FeatureVecotor;
 for (;itr!=features->end();++itr)        //循环获得所有特征
 {
  thefeature=(*itr); //获得特征赋值给featuresList
  //theSession->ListingWindow()->WriteLine("特征类型:"+thefeature->FeatureType()); //获得特征类型打印
  FeatureVecotor.push_back(thefeature->Tag());
 }

 //遍历体
 std::vector<tag_t> BodyVecotor;
 BodyCollection *bodys = workPart->Bodies();
 for (BodyCollection::iterator ite = bodys->begin();ite !=bodys->end();ite++)
 {
  Body *body=(*ite);
  BodyVecotor.push_back(body->Tag());
 }
 //移除体参数
 for ( int i=0;i<BodyVecotor.size();i++)
 {
  //移除参数
  Body *body1(dynamic_cast<Body *>(NXObjectManager::Get(BodyVecotor[i]))); //选择的目标转换
  Features::RemoveParametersBuilder *removeParametersBuilder1;

  removeParametersBuilder1 = workPart->Features()->CreateRemoveParametersBuilder();
  bool added1;
  added1 = removeParametersBuilder1->Objects()->Add(body1);

  NXObject *nXObject1;
  nXObject1 = removeParametersBuilder1->Commit();

  removeParametersBuilder1->Destroy();//释放 
 }

 //遍历line
 std::vector<tag_t> LineVecotor;
 LineCollection *lines = workPart->Lines();
 for (LineCollection::iterator linesite = lines->begin();linesite !=lines->end();linesite++)
 {
  Line *line =(*linesite);
  LineVecotor.push_back(line->Tag());
 }
 //移除线参数
 for ( int i=0;i<LineVecotor.size();i++)
 {
  //移除参数
  Line *line1(dynamic_cast<Line *>(NXObjectManager::Get(LineVecotor[i]))); //目标转换
  Features::RemoveParametersBuilder *removeParametersBuilder1;

  removeParametersBuilder1 = workPart->Features()->CreateRemoveParametersBuilder();
  bool added1;
  added1 = removeParametersBuilder1->Objects()->Add(line1);

  NXObject *nXObject1;
  nXObject1 = removeParametersBuilder1->Commit();

  removeParametersBuilder1->Destroy();//释放 
 }
 //遍历Arc
 std::vector<tag_t> ArcVecotor;
 ArcCollection *arcs = workPart->Arcs();
 for (ArcCollection::iterator arcsite = arcs->begin();arcsite !=arcs->end();arcsite++)
 {
  Arc *arc =(*arcsite);
  arc->Highlight();
  ArcVecotor.push_back(arc->Tag());
 }
 //移除圆弧参数
 for ( int i=0;i<ArcVecotor.size();i++)
 {
  //移除参数
  Arc *arc1(dynamic_cast<Arc *>(NXObjectManager::Get(ArcVecotor[i]))); //目标转换
  Features::RemoveParametersBuilder *removeParametersBuilder1;

  removeParametersBuilder1 = workPart->Features()->CreateRemoveParametersBuilder();
  bool added1;
  added1 = removeParametersBuilder1->Objects()->Add(arc1);

  NXObject *nXObject1;
  nXObject1 = removeParametersBuilder1->Commit();
  removeParametersBuilder1->Destroy();//释放 
 }

 //遍历point
 std::vector<tag_t> PointVecotor;
 PointCollection *points = workPart->Points();
 for (PointCollection::iterator pointsite = points->begin();pointsite !=points->end();pointsite++)
 {
  Point *point =(*pointsite);
  //point->Highlight();
  PointVecotor.push_back(point->Tag());
 }
 //移除点参数
 for ( int i=0;i<PointVecotor.size();i++)
 {
  //移除参数
  Point *point1(dynamic_cast<Point *>(NXObjectManager::Get(PointVecotor[i]))); //目标转换
  Features::RemoveParametersBuilder *removeParametersBuilder1;

  removeParametersBuilder1 = workPart->Features()->CreateRemoveParametersBuilder();
  bool added1;
  added1 = removeParametersBuilder1->Objects()->Add(point1);

  NXObject *nXObject1;
  nXObject1 = removeParametersBuilder1->Commit();
  removeParametersBuilder1->Destroy();//释放 
 }

 //遍历Spline
 std::vector<tag_t> SplineVecotor;
 SplineCollection *splines = workPart->Splines();
 for (SplineCollection::iterator splinesite = splines->begin();splinesite !=splines->end() ; splinesite++)
 {
  Spline *spline = (*splinesite);
  SplineVecotor.push_back(spline->Tag());
 }

 //移除Spline参数
 for ( int i=0;i<SplineVecotor.size();i++)
 {
  //移除参数
  Spline *spline1(dynamic_cast<Spline *>(NXObjectManager::Get(SplineVecotor[i]))); //目标转换
  Features::RemoveParametersBuilder *removeParametersBuilder1;

  removeParametersBuilder1 = workPart->Features()->CreateRemoveParametersBuilder();
  bool added1;
  added1 = removeParametersBuilder1->Objects()->Add(spline1);

  NXObject *nXObject1;
  nXObject1 = removeParametersBuilder1->Commit();
  removeParametersBuilder1->Destroy();//释放 
 }

 Features::Feature* thefeature2;
 Features::FeatureCollection *features2=workPart->Features();//迭代
 Features::FeatureCollection::iterator itr2=features->begin();//获得第一个特征
 std::vector<tag_t> FeatureVecotor2;
 for (;itr2!=features2->end();++itr2)        //循环获得所有特征
 {
  thefeature2=(*itr2); //获得特征赋值给featuresList
  //theSession->ListingWindow()->WriteLine("特征类型:"+thefeature->FeatureType()); //获得特征类型打印
  FeatureVecotor2.push_back(thefeature2->Tag());
 }

 char msg [256];
 sprintf ( msg , "工作部件共%d个特征, %d个特征完成移除参数。基准、已抑制的特征没能移除参数, 如有问题请反馈。",FeatureVecotor.size(),FeatureVecotor.size()-FeatureVecotor2.size());
 //uc1601(msg,0);

 if( count != 0 || LineVecotor.size() !=0 || ArcVecotor.size() !=0 || PointVecotor.size() !=0 || SplineVecotor.size() !=0 )
 {
  theUI->NXMessageBox()->Show("制作:Alan Huang    QQ:185266370", NXOpen::NXMessageBox::DialogTypeInformation, msg );
 }
 else
 {
  theUI->NXMessageBox()->Show("制作:Alan Huang    QQ:185266370", NXOpen::NXMessageBox::DialogTypeInformation, "未找到移除参数的对象, 如有问题请反馈。");
  //uc1601("未找到要移除参数的对象",1);
 }

 

posted on 2021-02-28 13:48  怡宁塑胶模具设计  阅读(532)  评论(0编辑  收藏  举报