admin 发表于 2013-11-4 16:53:51

UG NX 二次开发源码分享:遍历所有的实体得到边面特征信息

UG NX 二次开发源码分享:遍历所有的实体得到边面特征信息


theSession->ListingWindow()->Open();
theSession->ListingWindow()->WriteLine("Get information from all bodies\n");
   std::vector<Body *> bodies;
BodyCollection *bodyColl = workPart->Bodies();
for(it = bodyColl->begin();it!=bodyColl->end();++it)
{
   bodies.push_back(*it);
}
ss <<"Bodies count = " << bodies.size()<< "\n";
   std::vector <Edge *> edges;
   std::vector <Edge *> totalEdges;
   std::vector <Face *> faces;
   std::vector <Face *> totalfaces;
   std::vector <Features::Feature *> Features;
   std::vector <Features::Feature *> totalFeature;
   Point3d vertex1,vertex2;
   for (unsigned int i = 0; i< bodies.size();++i)
   {
    edges = bodies->GetEdges();
    faces = bodies->GetFaces();
    Features = bodies->GetFeatures();
   for(unsigned int j =0;j < edges.size(); j++)
   {
   totalEdges.push_back(edges);
   }
   for(unsigned int j =0;j < faces.size(); j++)
   {
   totalfaces.push_back(faces);
   }
      for(unsigned int j =0;j < Features.size(); j++)
   {
   totalFeature.push_back(Features);
   }
      
   }
    ss <<"edges count = " << totalEdges.size()<< "\n";
   for(unsigned int j =0;j < totalEdges.size(); j++)
   {   
      totalEdges->GetVertices(&vertex1,&vertex2);
       ss <<"edges tag: " <<totalEdges->GetBody()->GetTag()<<"\t";
       ss <<"edges vertex 1: "<<"("<<vertex1.X<<","<<vertex1.Y<<","<<vertex1.Z<<")"<<"\t";
       ss <<"edges vertex 2: "<<"("<<vertex2.X<<","<<vertex2.Y<<","<<vertex2.Z<<")"<<"\n";
   }
   ss <<"faces count = " << totalfaces.size()<< "\n";
    for(unsigned int j =0;j < totalfaces.size(); j++)
    {
   ss <<"Face tag: " << totalfaces->Tag()<<"\t";
   ss <<"Face Type: " << totalfaces->SolidFaceType()<<"\t";
   ss <<"Face Name: " <<totalfaces->Name().GetUTF8Text()<<"\n";
    }
   ss <<"Features count = " << totalFeature.size()<< "\n";
   for(unsigned int j =0;j < totalFeature.size(); j++)
    {
   ss <<"features tag : " << totalFeature->Tag()<<"\t";
   ss <<"features Type: " << totalFeature->FeatureType().GetUTF8Text()<<"\t";
   ss <<"features Name: " <<totalFeature->GetFeatureName().GetUTF8Text()<<"\n";
    }
theSession->ListingWindow()->WriteLine(ss.str());


查询结果如下:


Get information from all bodies
CYLINDERBodies count = 7
edges count = 22
edges tag: 41404 edges vertex 1: (100,0,0) edges vertex 2: (100,0,100)
edges tag: 41404 edges vertex 1: (100,0,0) edges vertex 2: (100,100,0)
edges tag: 41404 edges vertex 1: (0,100,0) edges vertex 2: (0,100,100)
edges tag: 41404 edges vertex 1: (100,100,0) edges vertex 2: (0,100,0)
edges tag: 41404 edges vertex 1: (100,0,100) edges vertex 2: (0,0,100)
edges tag: 41404 edges vertex 1: (0,0,0) edges vertex 2: (100,0,0)
edges tag: 41404 edges vertex 1: (100,100,0) edges vertex 2: (100,100,100)
edges tag: 41404 edges vertex 1: (0,100,100) edges vertex 2: (100,100,100)
edges tag: 41404 edges vertex 1: (0,0,100) edges vertex 2: (0,100,100)
edges tag: 41404 edges vertex 1: (100,100,100) edges vertex 2: (100,0,100)
edges tag: 41404 edges vertex 1: (0,0,0) edges vertex 2: (0,0,100)
edges tag: 41404 edges vertex 1: (0,100,0) edges vertex 2: (0,0,0)
edges tag: 40966 edges vertex 1: (50,0,100) edges vertex 2: (50,0,100)
edges tag: 40966 edges vertex 1: (50,0,200) edges vertex 2: (50,0,200)
edges tag: 40977 edges vertex 1: (50,0,200) edges vertex 2: (50,0,200)
edges tag: 40977 edges vertex 1: (50,0,300) edges vertex 2: (50,0,300)
edges tag: 37824 edges vertex 1: (50,0,300) edges vertex 2: (50,0,300)
edges tag: 37824 edges vertex 1: (50,0,400) edges vertex 2: (50,0,400)
edges tag: 41200 edges vertex 1: (50,0,400) edges vertex 2: (50,0,400)
edges tag: 41200 edges vertex 1: (50,0,500) edges vertex 2: (50,0,500)
edges tag: 41357 edges vertex 1: (150,100,200) edges vertex 2: (150,100,200)
edges tag: 41357 edges vertex 1: (150,100,100) edges vertex 2: (150,100,100)
faces count = 22
Face tag: 41407 Face Type: 4 Face Name:
Face tag: 41398 Face Type: 1 Face Name:
Face tag: 41376 Face Type: 1 Face Name:
Face tag: 41391 Face Type: 1 Face Name:
Face tag: 41380 Face Type: 1 Face Name:
Face tag: 41396 Face Type: 1 Face Name:
Face tag: 41397 Face Type: 1 Face Name:
Face tag: 40995 Face Type: 2 Face Name:
Face tag: 40965 Face Type: 1 Face Name:
Face tag: 40997 Face Type: 1 Face Name:
Face tag: 41351 Face Type: 1 Face Name:
Face tag: 41352 Face Type: 1 Face Name:
Face tag: 41353 Face Type: 2 Face Name:
Face tag: 38479 Face Type: 1 Face Name:
Face tag: 38480 Face Type: 1 Face Name:
Face tag: 38481 Face Type: 2 Face Name:
Face tag: 41207 Face Type: 1 Face Name:
Face tag: 41203 Face Type: 1 Face Name:
Face tag: 41158 Face Type: 2 Face Name:
Face tag: 40987 Face Type: 2 Face Name:
Face tag: 41010 Face Type: 1 Face Name:
Face tag: 41001 Face Type: 1 Face Name:
Features count = 7
features tag : 41280 features Type: SPHERE features Name: Sphere(17)
features tag : 41281 features Type: BLOCK features Name: Block(18)
features tag : 41307 features Type: CYLINDER features Name: Cylinder(19)
features tag : 41314 features Type: CYLINDER features Name: Cylinder(20)
features tag : 41322 features Type: CYLINDER features Name: Cylinder(21)
features tag : 41330 features Type: CYLINDER features Name: Cylinder(22)
features tag : 41338 features Type: CYLINDER features Name: Cylinder(23)

页: [1]
查看完整版本: UG NX 二次开发源码分享:遍历所有的实体得到边面特征信息