NX二次开发-获取NX里的对象信息

  • 以获取曲线的对象信息为例,实现代码如下。
 1 void GetCurveInfo(tag_t curve, vector<string> &infoStrings)
 2     {
 3         infoStrings.clear();
 4 
 5         if (curve == NULL_TAG)
 6         {
 7             return;
 8         }
 9 
10         DraftingCurve* draftingCurve = dynamic_cast<DraftingCurve*>(NXObjectManager::Get(curve));
11 
12         string fileName = HideListingDevice();
13 
14         vector<NXOpen::NXObject*> objs;
15         objs.push_back(draftingCurve);
16         GetSession()->Information()->DisplayObjectsDetails(objs);
17 
18         ShowListingDevice();
19 
20         if (!ReadFile(fileName, infoStrings))
21         {
22             return;
23         }
24 
25         fstream file(fileName, ios::out);
26     }
 1 void ShowListingDevice()
 2 {
 3         ListingWindow *lw = GetSession()->ListingWindow();
 4 
 5         if (lw->IsOpen())
 6         {
 7             lw->Close();
 8         }
 9 
10         lw->SelectDevice(ListingWindow::DeviceTypeWindow, "");
11 }
 1 string HideListingDevice()
 2 {
 3         ListingWindow *lw = GetSession()->ListingWindow();
 4 
 5         if (lw->IsOpen())
 6         {
 7             lw->Close();
 8         }
 9 
10         string tmpFileName = GetConfigDir() + "LineInfo.txt";  #将对象信息导入到txt文件里
12         fstream file(tmpFileName, ios::out);
13         lw->SelectDevice(ListingWindow::DeviceTypeFile, tmpFileName.c_str());
14 
15         return tmpFileName;
16 }

 

posted on 2020-12-14 13:09  不再低调  阅读(906)  评论(0编辑  收藏  举报