码迷,mamicode.com
首页 > 其他好文 > 详细

NX二次开发-NXOpen获取边的端点NXOpen::Edge::GetVertices

时间:2019-05-31 21:41:50      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:cat   isp   session   set   printf   type   length   转换   die   

 1     NX9+VS2012
 2     
 3     #include <NXOpen/Features_BlockFeatureBuilder.hxx>
 4     #include <NXOpen/Features_FeatureCollection.hxx>
 5     #include <NXOpen/NXException.hxx>
 6     #include <NXOpen/Body.hxx>
 7     #include <NXOpen/BodyCollection.hxx>
 8     #include <NXOpen/PartCollection.hxx>
 9     #include <NXOpen/Edge.hxx>
10     #include <NXOpen/ListingWindow.hxx>
11     #include <NXOpen/NXObjectManager.hxx>
12     #include <NXopen/UI.hxx>
13     #include <NXOpen/DisplayManager.hxx>
14     
15     using namespace NXOpen;
16 
17     NXOpen::Session *theSession = NXOpen::Session::GetSession();
18     NXOpen::Part *workPart(theSession->Parts()->Work());
19     NXOpen::Part *displayPart(theSession->Parts()->Display());
20 
21     ListingWindow *lw;
22     lw = theSession->ListingWindow();
23 
24 
25     //NXOpen方式创建块
26     NXOpen::Features::Feature *nullNXOpen_Features_Feature(NULL);
27     NXOpen::Features::BlockFeatureBuilder *blockFeatureBuilder1;
28     blockFeatureBuilder1 = workPart->Features()->CreateBlockFeatureBuilder(nullNXOpen_Features_Feature);
29 
30     std::vector<NXOpen::Body *> targetBodies1(1);
31     NXOpen::Body *nullNXOpen_Body(NULL);
32     targetBodies1[0] = nullNXOpen_Body;
33     blockFeatureBuilder1->BooleanOption()->SetTargetBodies(targetBodies1);
34 
35     blockFeatureBuilder1->SetType(NXOpen::Features::BlockFeatureBuilder::TypesOriginAndEdgeLengths);//设置创建类型
36 
37     NXOpen::Point3d originPoint1(120.0, 103.0, 154.0);
38     blockFeatureBuilder1->SetOriginAndLengths(originPoint1, "142", "132", "118");//设置原点
39 
40     blockFeatureBuilder1->SetBooleanOperationAndTarget(NXOpen::Features::Feature::BooleanTypeCreate, nullNXOpen_Body);//设置布尔
41 
42     NXOpen::Features::Feature *feature1;
43     feature1 = blockFeatureBuilder1->CommitFeature();
44 
45     
46 
47     //NXOpen方式设置颜色
48     NXOpen::DisplayModification *displayModification1;
49     displayModification1 = theSession->DisplayManager()->NewDisplayModification();
50 
51     displayModification1->SetNewColor(108);//设置颜色
52 
53     std::vector<NXOpen::DisplayableObject *> objects1(1);
54     NXOpen::Body *body1(dynamic_cast<NXOpen::Body *>(workPart->Bodies()->FindObject(feature1->JournalIdentifier())));
55     objects1[0] = body1;
56     displayModification1->Apply(objects1);
57 
58 
59     //NXOpen特征获取体
60     NXOpen::Body *MyBody(dynamic_cast<NXOpen::Body *>(workPart->Bodies()->FindObject(feature1->JournalIdentifier())));
61 
62 
63     //NXOpen体获取边
64     std::vector<NXOpen::Edge*> MyEdge = MyBody->GetEdges();
65     
66     char msg1[256];
67     char msg2[256];
68     sprintf_s(msg1, "当前体有%d条边\n每条边的两个端点如下:\n", MyEdge.size());//转换
69 
70     //打印
71     lw->Open();
72     lw->WriteLine(msg1);
73 
74     for (int i = 0; i < MyEdge.size(); i++)
75     {
76         MyEdge[i]->Highlight();//高亮所有边
77         NXOpen::Point3d Vertex1[3];//端点1
78         NXOpen::Point3d Vertex2[3];//端点2
79         MyEdge[i]->GetVertices(Vertex1, Vertex2);//由边获取端点
80     
81         sprintf_s(msg2, "X坐标:%.0f,  Y坐标:%.0f, Z坐标:%.0f\nX坐标:%.0f,  Y坐标:%.0f,  Z坐标:%.0f\n", Vertex1->X, Vertex1->Y, Vertex1->Z, Vertex2->X, Vertex2->Y, Vertex2->Z);//转换
82         lw->WriteLine(msg2);//打印
83     }

技术图片

NX二次开发-NXOpen获取边的端点NXOpen::Edge::GetVertices

标签:cat   isp   session   set   printf   type   length   转换   die   

原文地址:https://www.cnblogs.com/nxopen2018/p/10957467.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!