之前了解到通过UFUN函数UF_UGMGR_invoke_pdm_server可以调用Teamcenter ITK函数,从而可以获取及编辑Teamcenter对象。UFUN中有样例代码,但是就是不知道怎么使用,今天下午看了帮助文档,想到需要把ITK的USER_invoke_pdm_server函数进行注册,就进行测试,没想到给写通了。在此记录代码调试过程,转载请注明出处。

注意事项:

  1-需要了解Teamcenter Handler注册过程。

  2-Teamcenter开发方面可以参考微信公众号:PLMCODE

NX工程代码:

  1 //================================
2 // UF_UGMGR_invoke_pdm_server
3 //================================
4 //tcnx_project
5
6 // Mandatory UF Includes
7 #include <uf.h>
8 #include <uf_object_types.h>
9 #include <uf_draw.h>
10 #include <uf_part.h>
11 #include <uf_ugmgr.h>
12
13 #include <NXSigningResource.cpp>
14
15 // Internal Includes
16 #include <NXOpen/ListingWindow.hxx>
17 #include <NXOpen/NXMessageBox.hxx>
18 #include <NXOpen/UI.hxx>
19 #include <NXOpen/LogFile.hxx>
20
21 // Internal+External Includes\
22 #include <NXOpen/Annotations.hxx>
23 #include <NXOpen/Assemblies_Component.hxx>
24 #include <NXOpen/Assemblies_ComponentAssembly.hxx>
25 #include <NXOpen/Body.hxx>
26 #include <NXOpen/BodyCollection.hxx>
27 #include <NXOpen/Face.hxx>
28 #include <NXOpen/Line.hxx>
29 #include <NXOpen/NXException.hxx>
30 #include <NXOpen/NXObject.hxx>
31 #include <NXOpen/Part.hxx>
32 #include <NXOpen/PartCollection.hxx>
33 #include <NXOpen/Session.hxx>
34
35 #include <NXOpen/PDM_SoaConnectionHandle.hxx>
36 #include <NXOpen/PDM_PdmSession.hxx>
37 #include <NXOpen/PDM_PdmSearch.hxx>
38 #include <NXOpen/PDM_PdmFile.hxx>
39 #include <NXOpen/PDM_PdmNavigatorNode.hxx>
40 #include <NXOpen/PDM_PdmPart.hxx>
41 #include <NXOpen/PDM_PdmSearchManager.hxx>
42 #include <NXOpen/PDM_SoaQuery.hxx>
43 #include <NXOpen/PDM_SearchResult.hxx>
44
45 #include <NXOpen/PrintPDFBuilder.hxx>
46 #include <NXOpen/PlotManager.hxx>
47 #include <NXOpen/Drawings_DrawingSheet.hxx>
48 #include <NXOpen/NXObjectManager.hxx>
49
50 // Std C++ Includes
51 #include <iostream>
52 #include <sstream>
53 #include <vector>
54 #include <string>
55 #include <algorithm>
56 #include <tchar.h>
57 #include <atlconv.h>
58 #include <shellapi.h>
59
60 #include <windows.h>
61 #undef CreateDialog
62 #pragma comment(lib,"shell32.lib")
63
64 #define CREATION_DATE 1
65 #define MODIFICATION_DATE 2
66 #define MAX_UGMGR_NAME_LEN 1024
67
68 using namespace NXOpen;
69 using std::string;
70 using std::exception;
71 using std::stringstream;
72 using std::endl;
73 using std::cout;
74 using std::cerr;
75
76 NXOpen::ListingWindow *lw = NULL;
77 NXOpen::NXMessageBox *mb = NULL;
78
79 #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
80 int report_error(char *file, int line, char *call, int code)
81 {
82 if (code){
83 stringstream errmsg;
84 errmsg << "Error " << code << " in " << file << " at line " << line << endl;
85 errmsg << call << endl;
86 cerr << errmsg.str();
87 throw NXOpen::NXException::Create(code);
88 }
89 return(code);
90 }
91
92 void print(const NXString &);
93 void print(const string &);
94 void print(const char*);
95 int invokePdmServer();
96 int invokePdmServer()
97 {
98 int _errCode = 0;
99 _errCode = UF_CALL(UF_UGMGR_initialize(0, NULL));
100
101 char part_name[MAX_UGMGR_NAME_LEN + 1] = "000015200AA000000";
102 int output_code = -1;
103 char* date = NULL;
104
105 _errCode = UF_CALL(UF_UGMGR_invoke_pdm_server(CREATION_DATE, part_name, &output_code, &date));
106 print("\nAfter calling UF_UGMGR_invoke_pdm_server()\n");
107 print("Part : " + string(part_name));
108 print("creation date : " + string(date));
109 print("output_code : " + std::to_string(output_code) + "\n\n");
110 UF_free(date);
111 date = NULL;
112
113 UF_UGMGR_terminate();
114 return _errCode;
115 }
116
117 extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
118 {
119 try
120 {
121 invokePdmServer();
122 return;
123 }
124 catch (const NXException& e1)
125 {
126 UI::GetUI()->NXMessageBox()->Show("NXException", NXOpen::NXMessageBox::DialogTypeError, e1.Message());
127 }
128 catch (const exception& e2)
129 {
130 UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, e2.what());
131 }
132 catch (...)
133 {
134 UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, "Unknown Exception.");
135 }
136 }
137
138 extern "C" DllExport int ufusr_ask_unload()
139 {
140 return (int)NXOpen::Session::LibraryUnloadOptionImmediately;// 调试用
141 //return (int)NXOpen::Session::LibraryUnloadOptionAtTermination;// 程序发布用
142 //return (int)NXOpen::Session::LibraryUnloadOptionExplicitly;
143 }
144
145 void print(const NXString &msg)
146 {
147 if (!lw->IsOpen()) lw->Open();
148 lw->WriteLine(msg);
149 }
150 void print(const string &msg)
151 {
152 if (!lw->IsOpen()) lw->Open();
153 lw->WriteLine(msg);
154 }
155 void print(const char * msg)
156 {
157 if (!lw->IsOpen()) lw->Open();
158 lw->WriteLine(msg);
159 }

Teamcenter Handler工程代码:

 1 //======================================
2 // libA2CustStudy_register_callbacks
3 //======================================
4
5 //=======================
6 // libA2CustStudy.h
7 //=======================
8 #ifndef TCHANDLER_STUDY_H
9 #define TCHANDLER_STUDY_H
10
11 #pragma once
12 #include <bom/bom.h>
13 #include <ict/ict_userservice.h>
14 #include <epm\epm_access_control.h>
15 #include <epm\epm_task_template_itk.h>
16 #include <epm\epm.h>
17 #include <epm\epm_toolkit_iman_utils.h>
18 #include <epm/epm_toolkit_tc_utils.h>
19 #include <pie/sample_err.h>
20 #include <tc/tc.h>
21 #include <tc/iman.h>
22 #include <tccore/custom.h>
23 #include <tccore/aom_prop.h>
24 #include <user_exits/user_exits.h>
25 #include <tccore/workspaceobject.h>
26
27 #include <tccore/aom.h>
28 #include <tccore/item.h>
29 #include <base_utils/Mem.h>
30
31 #include "register_custom_user_service.h"
32
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38
39 extern DLLAPI int libA2CustStudy_register_callbacks();
40 int libA2CustStudy_invoke_pdm_server(int *decision, va_list args);
41
42 #ifdef __cplusplus
43 }
44 #endif
45
46 #endif
 1 //=======================
2 // libA2CustStudy.cpp
3 //=======================
4 #include "libA2CustStudy.h"
5
6 #define CUST_TCHANDLER_STUDY "libA2CustStudy"
7
8 extern DLLAPI int libA2CustStudy_register_callbacks()
9 {
10 int stat = ITK_ok;
11 stat = CUSTOM_register_exit(CUST_TCHANDLER_STUDY, "USER_invoke_pdm_server", (CUSTOM_EXIT_ftn_t)libA2CustStudy_invoke_pdm_server);
12 stat == ITK_ok ? printf("(libA2CustStudy.dll)-函数libA2CustStudy_invoke_pdm_server返回值为ITK_ok,注册成功!!!\n") : printf("(libA2CustStudy.dll)-函数libA2CustStudy_invoke_pdm_server返回值不等于ITK_ok,注册失败!!!\n");
13 return stat;
14 }
 1 //=======================
2 // lib_register_custom.cpp
3 //=======================
4 #include "libA2CustStudy.h"
5
6 #define CREATION_DATE 1
7 #define MODIFICATION_DATE 2
8
9 #ifdef __cplusplus
10 extern "C"
11 {
12 #endif
13
14 int libA2CustStudy_invoke_pdm_server(int *decision, va_list args)
15 {
16 /*********** va_list for USER_invoke_pdm_server ***********/
17 int input_code = va_arg(args, int); /* args 1 */
18 char *input_string = va_arg(args, char *); /* args 2 */
19 int *output_code = va_arg(args, int *); /* args 3 */
20 char **output_string = va_arg(args, char **); /* args 4 */
21 /***********************************************************/
22 printf("\t libA2CustStudy_invoke_pdm_server \n\n");
23 *decision = ALL_CUSTOMIZATIONS;
24
25 tag_t item_tag;
26 int itkfail;
27 WSO_description_t description;
28 char createDate[WSO_date_size_c + 1];
29 char modifyDate[WSO_date_size_c + 1];
30 char objectName[WSO_date_size_c + 1];
31 char objectType[WSO_date_size_c + 1];
32 char ownersName[WSO_date_size_c + 1];
33 char owning_group_name[WSO_date_size_c + 1];
34 char last_modify_user_name[WSO_date_size_c + 1];
35 char object_desc[WSO_date_size_c + 1];
36 *output_code = 0;
37 char tmp_output_string[1024] = { 0 };
38
39 itkfail = ITEM_find_item(input_string, &item_tag);
40 if (itkfail != ITK_ok){
41 printf("Failed to find item %s\n", input_string);
42 *output_code = 1;
43 }
44
45 itkfail = WSOM_describe(item_tag, &description);
46 if (itkfail != ITK_ok){
47 printf("Failed to get description of the item\n");
48 *output_code = 1;
49 }
50
51 printf("ITK USER_invoke_pdm_server() routine :\n");
52 printf("INPUT:\n");
53 printf("input_code : %d\n", input_code);
54 printf("input_string : %s\n\n", input_string);
55
56 switch (input_code){
57 case CREATION_DATE:
58 case MODIFICATION_DATE:
59 strcpy_s(object_desc, strlen(description.date_created) + 1, description.description);
60 strcpy_s(createDate, strlen(description.date_created) + 1, description.date_created);
61 strcpy_s(modifyDate, strlen(description.date_modified) + 1, description.date_modified);
62 strcpy_s(objectName, strlen(description.object_name) + 1, description.object_name);
63 strcpy_s(objectType, strlen(description.object_type) + 1, description.object_type);
64 strcpy_s(ownersName, strlen(description.owners_name) + 1, description.owners_name);
65 strcpy_s(owning_group_name, strlen(description.owning_group_name) + 1, description.owning_group_name);
66 strcpy_s(last_modify_user_name, strlen(description.last_modifying_user_name) + 1, description.last_modifying_user_name);
67 sprintf_s(tmp_output_string, "date_created=%s\ndate_modified=%s\nobject_name=%s\nobject_type=%s\nowners_name=%s\nowning_group_name=%s\nlast_modify_user_name=%s\nobject_desc=%s\n",
68 createDate, modifyDate, objectName, objectType, ownersName, owning_group_name, last_modify_user_name, object_desc);
69 break;
70 default:
71 printf("OUTPUT:该参数 %d 未定义操作!\n", input_code);
72 break;
73 }
74 if (strlen(tmp_output_string) > 0){
75 *output_string = (char*)malloc(sizeof(tmp_output_string));
76 strcpy_s(*output_string, strlen(tmp_output_string) + 1, tmp_output_string);
77 printf("OUTPUT:\n");
78 printf("output_string : %s (%s)\n", *output_string, (input_code == 1) ? "CREATION DATE" : "MODIFICATION DATE");
79 printf("output_code : %d\n", *output_code);
80 }
81 return ITK_ok;
82 }
83
84 #ifdef __cplusplus
85 }
86 #endif

Teamcenter零组件属性截图:

工程调试运行GIF动图:

2023年03月25日 16点52分发布。转载请注明出处!!!

Teamcenter_NX集成开发:UF_UGMGR_invoke_pdm_server函数的使用的更多相关文章

  1. 【超全整理】J2EE集成开发环境MyEclipse使用心得汇总

    一.首先我们为什么需要MyEclipse? 下面允许我做一些简要的介绍: 应该大家都知道另一个MyEclipse的近亲——Eclipse的优点:免费.程序代码排版功能.有中文汉化包.可增设许多功能强大 ...

  2. 【转】windows和linux中搭建python集成开发环境IDE

    本系列分为两篇: 1.[转]windows和linux中搭建python集成开发环境IDE 2.[转]linux和windows下安装python集成开发环境及其python包 3.windows和l ...

  3. 15 款最好的 C/C++ 编译器和集成开发环境

    我们有很多编程语言来进行 web 开发,比如 Java,.Net,PHP,Ruby,Perl,Python 等等.今天我们主要讨论的是两大古老而又流行的语言: C 和 C++ ,它们有着许多卓越的特性 ...

  4. ENVI/IDL与ArcGIS集成开发的三种途径

    转载:本文来自ENVI5.0-IDL8.2系列产品白皮书_201303.PDF(Esri中国官网可下载)中P7-P10 ENVI 是一个非常开放的平台,提供一个健全的函数库,几乎涵盖ENVI 平台大部 ...

  5. VC6集成开发环境使用参考

    VC6集成开发环境使用参考 1.VC6的常用菜单命令项 (1)File菜单 New:打开“new”对话框,以便创建新的文件.工程或工作区. Close Workspace:关闭与工作区相关的所有窗口. ...

  6. 手把手教你安装QT集成开发环境(操作系统为ubuntu10.04)

    在安装QT集成开发工具包之前需要先安装build-essential和libncurses5-dev这两个开发工具和库,libncurses5-dev库是一个在Linux/Unix下广泛应用的图形函数 ...

  7. windows和linux在建筑python集成开发环境IDE

    http://blog.csdn.net/pipisorry/article/details/39854707 使用的系统及软件 Ubuntu / windows Python 2.7 / pytho ...

  8. Java开发知识之Java的集成开发环境

    Java开发知识之Java的集成开发环境 一丶Eclipse 开发环境 Eclipse是IBM公司花了4000万美金开发的一个集成开发环境.是一个免费开源的. 下载官网: http://www.ecl ...

  9. linux集成开发环境

    Linux操作系统的种种集成开发环境 随着Linux的逐渐兴起,已经有为数众多的程序在上面驰骋了,许多开发环境(Development Environment)也应运而生.好的开发环境一定是集成了编辑 ...

  10. Linux操作系统的种种集成开发环境

    Linux操作系统的种种集成开发环境 随着Linux的逐渐兴起,已经有为数众多的程序在上面驰骋了,许多开发环境(Development Environment)也应运而生.好的开发环境一定是集成了编辑 ...

随机推荐

  1. 运行代码后出现Process finished with exit code 0

    pycharm_运行不出结果,也不报错_Process finished with exit code 0用pycharm运行程序的时候,运行不出结果 ,也不报错,且正常退出解决1:将 run → e ...

  2. 安卓蓝牙协议栈中的RFCOMM状态机分析

    1.1 数据结构 1.1.1  tRFC_MCB tRFC_MCB(type of rfcomm multiplexor control block的简写)代表了一个多路复用器.代表了RFCOMM规范 ...

  3. c++ vtdcm对于压缩模式文档图片的读取

    //获取dcm数据结构,一下图像数据仅针对单通道8字节数据 DcmFileFormat fileformat; OFCondition oc = fileformat.loadFile(dcmPath ...

  4. 获取指定字符串第n次出现的位置索引

    returnIndex(str,cha,num){ var x=str.indexOf(cha); for(var i=0;i<num;i++){ x=str.indexOf(cha,x+1); ...

  5. deepin系统编辑pdf文件的两个简单方法(终端命令行模式)

    DEEPIN深度系统编辑PDF文件有时竟然超级简单好用,比WINDOWS系统需要单独下载一个PDF编辑软件的方法强多了,而且windows系统PDF编辑软件还有版权限制,各种作啊. 下面的两条命令,使 ...

  6. 内存、cpu、硬盘使用率测试方法

    平时测试过程中经常需要测试页面展示的系统资源信息是否正确,比如CPU.内存.硬盘等,一般是需要测试服务器的资源情况,服务器一般部署在linux上,今天总结一下测试方法: 1.CPU测试:(使用shel ...

  7. js 获取html加载的参数?file=123&time=2021

    <script> function GetArgsFromHref(sHref, sArgName) { var args = sHref.split("?"); va ...

  8. 区分 PaaS、IaaS 、SaaS

  9. Vue3 animate.css + wowjs 官网实现滚动到对应元素位置增加动画特效

    本人在Vue3中使用的是 setup语法糖 也就是 <script setup>...</ script> 在项目中install一下两个插件: yarn add animat ...

  10. 问题记录04:记录两种C#引用C++DLL报错的解决方法。

    两种C#引用C++DLL报错的解决方法 无法加载DLL"***.dll":找不到指定的模块(异常来自HRESULT:0x8007007E) 解决方法:参考链接 试图加载格式不正确的 ...