Teamcenter_NX集成開發:通過NXOpen查詢零組件是否存在

来源:https://www.cnblogs.com/huangym1/archive/2023/03/24/17252660.html
-Advertisement-
Play Games

之前用過NXOpen PDM的命名空間下的類,現在記錄一下通過PDM命名空間下的類查詢Teamcenter零組件的信息,也可以用來判斷該零組件是否存在。 1-該工程為DLL工程,直接在NX界面調用,所以直接獲取NXSession。 2-查詢函數advanced用到的查詢為:__NX_STD_ANY_ ...


之前用過NXOpen PDM的命名空間下的類,現在記錄一下通過PDM命名空間下的類查詢Teamcenter零組件的信息,也可以用來判斷該零組件是否存在。

1-該工程為DLL工程,直接在NX界面調用,所以直接獲取NXSession。

2-查詢函數advanced用到的查詢為:__NX_STD_ANY_ITEM_QUERY,可以在Teamcenter查詢構建器模塊中看到該查詢。

 

  1 // Mandatory UF Includes
  2 #include <uf.h>
  3 #include <uf_object_types.h>
  4 
  5 // Internal Includes
  6 #include <NXOpen/ListingWindow.hxx>
  7 #include <NXOpen/NXMessageBox.hxx>
  8 #include <NXOpen/UI.hxx>
  9 #include <NXOpen/LogFile.hxx>
 10 
 11 // Internal+External Includes
 12 #include <NXOpen/Annotations.hxx>
 13 #include <NXOpen/Assemblies_Component.hxx>
 14 #include <NXOpen/Assemblies_ComponentAssembly.hxx>
 15 #include <NXOpen/Body.hxx>
 16 #include <NXOpen/BodyCollection.hxx>
 17 #include <NXOpen/Face.hxx>
 18 #include <NXOpen/Line.hxx>
 19 #include <NXOpen/NXException.hxx>
 20 #include <NXOpen/NXObject.hxx>
 21 #include <NXOpen/Part.hxx>
 22 #include <NXOpen/PartCollection.hxx>
 23 #include <NXOpen/Session.hxx>
 24 
 25 #include <NXOpen/PDM_SoaConnectionHandle.hxx>
 26 #include <NXOpen/PDM_PdmSession.hxx>
 27 #include <NXOpen/PDM_PdmSearch.hxx>
 28 #include <NXOpen/PDM_PdmFile.hxx>
 29 #include <NXOpen/PDM_PdmNavigatorNode.hxx>
 30 #include <NXOpen/PDM_PdmPart.hxx>
 31 #include <NXOpen/PDM_PdmSearchManager.hxx>
 32 #include <NXOpen/PDM_SoaQuery.hxx>
 33 #include <NXOpen/PDM_SearchResult.hxx>
 34 
 35 // Std C++ Includes
 36 #include <iostream>
 37 #include <sstream>
 38 
 39 using namespace NXOpen;
 40 using std::string;
 41 using std::exception;
 42 using std::stringstream;
 43 using std::endl;
 44 using std::cout;
 45 using std::cerr;
 46 
 47 NXOpen::ListingWindow *lw = NULL;
 48 NXOpen::NXMessageBox *mb = NULL;
 49 
 50 void do_it();
 51 void print(const NXString &);
 52 void print(const string &);
 53 void print(const char*);
 54 void showClickMessage(int &iRet);
 55 
 56 //------------------------------------------------------------------------------
 57 // Entry point(s) for unmanaged internal NXOpen C/C++ programs
 58 //------------------------------------------------------------------------------
 59 extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
 60 {
 61     try
 62     {
 63         // 獲取NXSession並初始化
 64         NXOpen::Session *theSession = NXOpen::Session::GetSession();
 65         NXOpen::UI *theUI = NXOpen::UI::GetUI();
 66         NXOpen::Part *displayPart(theSession->Parts()->Display());
 67         NXOpen::PDM::PdmSession * pdmSession = theSession->PdmSession();
 68         NXOpen::LogFile *lf = theSession->LogFile();    
 69         lw = theSession->ListingWindow();    
 70         mb = theUI->NXMessageBox();        
 71 
 72         // 獲取設置數據
 73         bool isSsoEnabled;
 74         NXOpen::NXString ssoServerUrl;
 75         NXOpen::NXString ssoAppID;
 76         NXOpen::NXString connectString;
 77         NXOpen::NXString discriminator;
 78         pdmSession->GetSsoSettings(&isSsoEnabled, &ssoServerUrl, &ssoAppID);
 79         pdmSession->GetTcserverSettings(&connectString, &discriminator);
 80     
 81         // 查詢Teamcenter中零組件 000015200AA000000
 82         NXOpen::PDM::PdmSearchManager *pdmSearchManager = theSession->PdmSearchManager();
 83         NXOpen::PDM::PdmSearch *pdmSearch = pdmSearchManager->NewPdmSearch();
 84         std::vector<NXOpen::NXString> entries;
 85         std::vector<NXOpen::NXString> values;
 86         entries.push_back("item_id");
 87         values.push_back("000015200AA000000");
 88         NXOpen::PDM::SearchResult * advancedSearchResults = pdmSearch->Advanced(entries, values);
 89         if (advancedSearchResults == NULL)
 90             return;
 91         std::vector<NXString> resultMfkIds = advancedSearchResults->GetResultMfkIds();
 92         std::vector<NXString> resultObjectNames = advancedSearchResults->GetResultObjectNames();
 93         std::vector<NXString> resultObjectTypes = advancedSearchResults->GetResultObjectTypes();
 94 
 95         // 輸出查詢到零組件的信息到信息框
 96         print("輸出查詢到零組件的信息到信息框");
 97         for (int idx = 0; idx < (int)resultMfkIds.size(); idx++){
 98             print("resultMfkIds = " + resultMfkIds[idx]);
 99             lf->WriteLine("resultMfkIds = " + resultMfkIds[idx]);
100         }
101         for (int idx = 0; idx < (int)resultObjectNames.size(); idx++){
102             print("resultObjectNames = " + resultObjectNames[idx]);
103             lf->WriteLine("resultObjectNames = " + resultObjectNames[idx]);
104         }
105         for (int idx = 0; idx < (int)resultObjectTypes.size(); idx++){
106             print("resultObjectTypes = " + resultObjectTypes[idx]);
107             lf->WriteLine("resultObjectTypes = " + resultObjectTypes[idx]);
108         }
109     
110         print("輸出信息到信息框");
111         print("ssoAppID = " + ssoAppID);
112         print("ssoServerUrl = " + ssoServerUrl);
113         print("connectString = " + connectString);
114         print("discriminator = " + discriminator);
115         
116         // 輸出信息到日誌文件
117         print("輸出信息到日誌文件");
118         lf->WriteLine("LogFileName = " + lf->FileName());
119         lf->WriteLine("ssoServerUrl = " + ssoServerUrl);
120         lf->WriteLine("ssoAppID = " + ssoAppID);
121         lf->WriteLine("connectString = " + connectString);
122         lf->WriteLine("discriminator = " + discriminator);
123 
124         // 輸出查詢到零組件的信息到提示框
125         int iRet = mb->Show("resultMfkIds", NXOpen::NXMessageBox::DialogTypeError, resultMfkIds);
126         showClickMessage(iRet);
127         iRet = mb->Show("resultObjectNames", NXOpen::NXMessageBox::DialogTypeWarning, resultObjectNames);
128         showClickMessage(iRet);
129         iRet = mb->Show("resultObjectTypes", NXOpen::NXMessageBox::DialogTypeInformation, resultObjectTypes);
130         showClickMessage(iRet);
131         iRet = mb->Show("resultObjectTypes", NXOpen::NXMessageBox::DialogTypeQuestion, resultObjectTypes);
132         showClickMessage(iRet);
133     }
134     catch (const NXException& e1)
135     {
136         UI::GetUI()->NXMessageBox()->Show("NXException", NXOpen::NXMessageBox::DialogTypeError, e1.Message());
137     }
138     catch (const exception& e2)
139     {
140         UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, e2.what());
141     }
142     catch (...)
143     {
144         UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, "Unknown Exception.");
145     }
146 }
147 
148 
149 //------------------------------------------------------------------------------
150 // Unload Handler
151 //------------------------------------------------------------------------------
152 extern "C" DllExport int ufusr_ask_unload()
153 {
154     return (int)NXOpen::Session::LibraryUnloadOptionImmediately;// 調試用
155     //return (int)NXOpen::Session::LibraryUnloadOptionAtTermination;// 程式發佈用
156     //return (int)NXOpen::Session::LibraryUnloadOptionExplicitly;
157 }
158 
159 void showClickMessage(int &iRet){
160     if (iRet == 1){
161         mb->Show("提示", NXOpen::NXMessageBox::DialogTypeInformation, "你點擊了是");
162     }
163     else if (iRet == 2){
164         mb->Show("提示", NXOpen::NXMessageBox::DialogTypeInformation, "你點擊了否");
165     }
166     else if (iRet == -2){
167         mb->Show("提示", NXOpen::NXMessageBox::DialogTypeInformation, "你點擊了確定");
168     }
169 }
170 
171 void print(const NXString &msg)
172 {
173     if (!lw->IsOpen()) lw->Open();
174     lw->WriteLine(msg);
175 }
176 void print(const string &msg)
177 {
178     if (!lw->IsOpen()) lw->Open();
179     lw->WriteLine(msg);
180 }
181 void print(const char * msg)
182 {
183     if (!lw->IsOpen()) lw->Open();
184     lw->WriteLine(msg);
185 }

 

程式執行後截圖:

 

 

 

 

 

 

 

GIF動圖:

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • title: "modern C++ DesignPattern-Part3" date: 2018-04-12T19:08:49+08:00 lastmod: 2018-04-12T19:08:49+08:00 keywords: [設計模式, C++] tags: [設計模式] categori ...
  • 關於指針、數組、字元串的恩怨,這裡有你想知道的一切 記憶體組成、字元串定義、一/二維數組結構、數組中的指針等價關係、數組結構中對“指針常量”的理解、 指針 vs 數組 記憶體結構一圖流、One More Thing:當二維數組遇見qsort()庫函數,關於比較函數cmp的迷思 ...
  • 模型和基本欄位 在上一章的末尾,我們創建一個odoo模塊。然而,此時它仍然是一個空殼,不允許我們存儲任何數據。在我們的房地產模塊中,我們希望將與房地產相關的信息(名稱(name)、描述(description)、價格(price)、居住面積(living area)…)存儲在資料庫中。odoo框架提 ...
  • 該工程為在保存時執行開發的功能,函數入口點ufput。其他還有新建、打開、另存等都可以加入開發的操作,具體看UF_EXIT下的介紹。 用戶出口是一個可選特性,允許你在NX中某些預定義的位置(或出口)自動運行Open C API程式。如果你進入其中一個出口,NX會檢查你是否定義了指向Open C AP ...
  • 網站介紹 基於 python 開發的電子商城網站,平臺採用 B/S 結構,後端採用主流的 Python 語言進行開發,前端採用主流的 Vue.js 進行開發。這是給師弟開發的畢業設計。 整個平臺包括前臺和後臺兩個部分。 前臺功能包括:首頁、商品詳情頁、用戶中心模塊。 後臺功能包括:總覽、訂單管理、商 ...
  • SpringBoot資料庫操作 1.JDBC+HikariDataSource 在SpringBoot 2.x項目中,預設使用Hikari連接池管理數據源。相比於傳統的 C3P0 、DBCP、Tomcat jdbc 等連接池更加優秀。 當項目pom.xml引入spring-boot-starter- ...
  • 一個新應用 房地產廣告模塊 假設需要開發一個房地產模塊,該模塊覆蓋未包含在標準模塊集中特定業務領域。 以下為包含一些廣告的主列表視圖 form視圖頂層區域概括了房產的重要信息,比如name,Property Type, Postcode等等。 列表記錄詳情頁中,第一個tab包含了房產的描述信息,比如 ...
  • 生產者消費者問題 簡介 生產者消費者模式並不是GOF提出的23種設計模式之一,23種設計模式都是建立在面向對象的基礎之上的,但其實面向過程的編程中也有很多高效的編程模式,生產者消費者模式便是其中之一,它是我們編程過程中最常用的一種設計模式。 在實際的軟體開發過程中,經常會碰到如下場景:某個模塊負責產 ...
一周排行
    -Advertisement-
    Play Games
  • C#TMS系統代碼-基礎頁面BaseCity學習 本人純新手,剛進公司跟領導報道,我說我是java全棧,他問我會不會C#,我說大學學過,他說這個TMS系統就給你來管了。外包已經把代碼給我了,這幾天先把增刪改查的代碼背一下,說不定後面就要趕鴨子上架了 Service頁面 //using => impo ...
  • 委托與事件 委托 委托的定義 委托是C#中的一種類型,用於存儲對方法的引用。它允許將方法作為參數傳遞給其他方法,實現回調、事件處理和動態調用等功能。通俗來講,就是委托包含方法的記憶體地址,方法匹配與委托相同的簽名,因此通過使用正確的參數類型來調用方法。 委托的特性 引用方法:委托允許存儲對方法的引用, ...
  • 前言 這幾天閑來沒事看看ABP vNext的文檔和源碼,關於關於依賴註入(屬性註入)這塊兒產生了興趣。 我們都知道。Volo.ABP 依賴註入容器使用了第三方組件Autofac實現的。有三種註入方式,構造函數註入和方法註入和屬性註入。 ABP的屬性註入原則參考如下: 這時候我就開始疑惑了,因為我知道 ...
  • C#TMS系統代碼-業務頁面ShippingNotice學習 學一個業務頁面,ok,領導開完會就被裁掉了,很突然啊,他收拾東西的時候我還以為他要旅游提前請假了,還在尋思為什麼回家連自己買的幾箱飲料都要叫跑腿帶走,怕被偷嗎?還好我在他開會之前拿了兩瓶芬達 感覺感覺前面的BaseCity差不太多,這邊的 ...
  • 概述:在C#中,通過`Expression`類、`AndAlso`和`OrElse`方法可組合兩個`Expression<Func<T, bool>>`,實現多條件動態查詢。通過創建表達式樹,可輕鬆構建複雜的查詢條件。 在C#中,可以使用AndAlso和OrElse方法組合兩個Expression< ...
  • 閑來無聊在我的Biwen.QuickApi中實現一下極簡的事件匯流排,其實代碼還是蠻簡單的,對於初學者可能有些幫助 就貼出來,有什麼不足的地方也歡迎板磚交流~ 首先定義一個事件約定的空介面 public interface IEvent{} 然後定義事件訂閱者介面 public interface I ...
  • 1. 案例 成某三甲醫預約系統, 該項目在2024年初進行上線測試,在正常運行了兩天後,業務系統報錯:The connection pool has been exhausted, either raise MaxPoolSize (currently 800) or Timeout (curren ...
  • 背景 我們有些工具在 Web 版中已經有了很好的實踐,而在 WPF 中重新開發也是一種費時費力的操作,那麼直接集成則是最省事省力的方法了。 思路解釋 為什麼要使用 WPF?莫問為什麼,老 C# 開發的堅持,另外因為 Windows 上已經裝了 Webview2/edge 整體打包比 electron ...
  • EDP是一套集組織架構,許可權框架【功能許可權,操作許可權,數據訪問許可權,WebApi許可權】,自動化日誌,動態Interface,WebApi管理等基礎功能於一體的,基於.net的企業應用開發框架。通過友好的編碼方式實現數據行、列許可權的管控。 ...
  • .Net8.0 Blazor Hybird 桌面端 (WPF/Winform) 實測可以完整運行在 win7sp1/win10/win11. 如果用其他工具打包,還可以運行在mac/linux下, 傳送門BlazorHybrid 發佈為無依賴包方式 安裝 WebView2Runtime 1.57 M ...