最近工作中经常使用Teamcenter、NX集成开发的情况,因此在这里记录UF_UGMGR函数的使用。使用UF_UGMGR相关函数需要有Teamcenter使用经验,理解Teamcenter中文件夹、伪文件夹、零组件、零组件版本、数据集、关系、表单、命名引用等对象。
相关的可以看帮助中 Teamcenter Integration for NX的内容 及 UF_UGMGR Overview 介绍的数据模型及使用方法、注意事项。
主要操作:
1-初始化UGMGR环境成功后就可以连接到Teamcenter。
2-获取指定ID编码零组件标识和Latest Working(没记错的话应该是最新版本)版本ID。
3-UF_UGMGR相关函数使用
1 // Mandatory UF Includes 2 #include <uf.h> 3 #include <uf_object_types.h> 4 #include <uf_ugmgr.h> 5 #include <uf_part.h> 6 #include <uf_disp.h> 7 #include <uf_modl.h> 8 #include <uf_obj.h> 9 #include <uf_assem.h> 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_PdmSession.hxx> 26 #include <NXOpen/PDM_SoaConnectionHandle.hxx> 27 #include <teamcenter/soa/client/Connection.hxx> 28 #include <teamcenter/services/core/DatamanagementService.hxx> 29 #include <teamcenter/soa/common/Version.hxx> 30 31 // Std C++ Includes 32 #include <iostream> 33 #include <sstream> 34 #include <stdio.h> 35 #include <stdlib.h> 36 37 using namespace NXOpen; 38 using namespace Teamcenter::Soa::Client; 39 using namespace Teamcenter::Services::Core; 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 static int indent_level = 0; 48 49 #define CHECK( func_ ) \ 50 ifail = (func_); \ 51 if (ifail != 0) {\ 52 printf("ERROR: %s returned %d", # func_, ifail); \ 53 return ifail;} 54 55 #define PRINT( content_ ) \ 56 { int ii; \ 57 for (ii = 0; ii < indent_level; ii++) \ 58 { printf(" "); } \ 59 printf content_; \ 60 printf("\n"); } 61 62 static int list_in_part(UF_UGMGR_tag_t part) 63 { 64 int _errCode = 0; 65 UF_UGMGR_tag_t* revisions; 66 int i, j, k; 67 int count; 68 int dep_count; 69 int rev_count; 70 char** names; 71 char** file_types; 72 char** file_names; 73 char part_name[MAX_FSPEC_SIZE + 1]; 74 char revision_id[UF_UGMGR_NAME_SIZE + 1]; 75 char part_number[UF_UGMGR_NAME_SIZE + 1]; 76 if (part == UF_UGMGR_null_tag) 77 return -1; 78 79 _errCode = UF_UGMGR_ask_part_number(part, part_number);// 获取零组件ItemID 80 PRINT(("Part: %s", part_number)); 81 indent_level++; 82 _errCode = UF_UGMGR_list_part_revisions(part, &rev_count, &revisions);// 获取零组件所有版本 83 for (j = 0; j < rev_count; j++) 84 { 85 _errCode = UF_UGMGR_ask_part_revision_id(revisions[j], revision_id);// 获取版本ID 86 _errCode = UF_UGMGR_encode_part_filename(part_number, revision_id, "", "", part_name);// encode文件名 87 PRINT(("Rev.: %s - Type: %s", revision_id, "master")); 88 indent_level++; 89 90 _errCode = UF_UGMGR_ask_dependent_files(part_name, &dep_cou