获取面面积,资料来自录制和网友分享

 1 #include <NXOpen/MeasureBuilder.hxx>
 2 #include <NXOpen/MeasureFaceBuilder.hxx>
 3 #include <NXOpen/MeasureFaces.hxx>
 4 #include <NXOpen/Unit.hxx>
 5 #include <NXOpen/UnitCollection.hxx>
 6 #include <NXOpen/NXObject.hxx>
 7 #include <NXOpen/NXObjectManager.hxx>
 8 
 9 double GetFaceArea(Face* face)//获取面积
10 {
11     Session* theSession = Session::GetSession();
12     Part* workPart(theSession->Parts()->Work());
13     Part* displayPart(theSession->Parts()->Display());
14     NXObject* nullNXObject(NULL);
15     NXOpen::MeasureFaceBuilder* measureFaceBuilder1;
16     measureFaceBuilder1 = workPart->MeasureManager()->CreateMeasureFaceBuilder(nullNXObject);
17     std::vector<IParameterizedSurface*> objects1(1);
18     objects1[0] = face;
19     MeasureFaces* measureFaces1;
20     measureFaces1 = workPart->MeasureManager()->NewFaceProperties(NULL, NULL, 0.9999, objects1);
21     measureFaceBuilder1->Commit();
22     ///measureFaceBuilder1->FaceObjects()->Clear();
23     measureFaceBuilder1->Destroy();
24     theSession->CleanUpFacetedFacesAndEdges();
25     double areaValue = measureFaces1->Area();
26     return areaValue;
27 }
28 
29 double GetFaceArea(tag_t face)//获取面积//重载tag_t
30 {
31     Session* theSession = Session::GetSession();
32     Part* workPart(theSession->Parts()->Work());
33     Part* displayPart(theSession->Parts()->Display());
34     NXObject* nullNXObject(NULL);
35     NXOpen::MeasureFaceBuilder* measureFaceBuilder1;
36     measureFaceBuilder1 = workPart->MeasureManager()->CreateMeasureFaceBuilder(nullNXObject);
37     std::vector<IParameterizedSurface*> objects1(1);
38     objects1[0] = dynamic_cast<NXOpen::Face*>(NXObjectManager::Get(face));
39     //NXOpen::Unit* unit1(dynamic_cast<NXOpen::Unit*>(workPart->UnitCollection()->FindObject("SquareMilliMeter")));
40     //NXOpen::Unit* unit2(dynamic_cast<NXOpen::Unit*>(workPart->UnitCollection()->FindObject("MilliMeter")));
41     MeasureFaces* measureFaces1;
42     measureFaces1 = workPart->MeasureManager()->NewFaceProperties(NULL, NULL, 0.9999, objects1);
43     measureFaceBuilder1->Commit();
44     ///measureFaceBuilder1->FaceObjects()->Clear();
45     measureFaceBuilder1->Destroy();
46     theSession->CleanUpFacetedFacesAndEdges();
47     double areaValue = measureFaces1->Area();
48     return areaValue;
49 }

 

posted @ 2020-09-16 13:56  老婆饼里有老婆  阅读(343)  评论(1编辑  收藏  举报