|
之前了解到通过UFUN函数UF_UGMGR_invoke_pdm_server可以调用Teamcenter ITK函数,从而可以获取及编辑Teamcenter对象。UFUN中有样例代码,但是就是不知道怎么使用,今天下午看了帮助文档,想到需要把ITK的USER_invoke_pdm_server函数进行注册,就进行测试,没想到给写通了。在此记录代码调试过程,转载请注明出处。 注意事项:
NX工程代码: - //================================
- // UF_UGMGR_invoke_pdm_server
- //================================
- //tcnx_project
- // Mandatory UF Includes
- #include <uf.h>
- #include <uf_object_types.h>
- #include <uf_draw.h>
- #include <uf_part.h>
- #include <uf_ugmgr.h>
- #include <NXSigningResource.cpp>
- // Internal Includes
- #include <NXOpen/ListingWindow.hxx>
- #include <NXOpen/NXMessageBox.hxx>
- #include <NXOpen/UI.hxx>
- #include <NXOpen/LogFile.hxx>
- // Internal+External Includes\
- #include <NXOpen/Annotations.hxx>
- #include <NXOpen/Assemblies_Component.hxx>
- #include <NXOpen/Assemblies_ComponentAssembly.hxx>
- #include <NXOpen/Body.hxx>
- #include <NXOpen/BodyCollection.hxx>
- #include <NXOpen/Face.hxx>
- #include <NXOpen/Line.hxx>
- #include <NXOpen/NXException.hxx>
- #include <NXOpen/NXObject.hxx>
- #include <NXOpen/Part.hxx>
- #include <NXOpen/PartCollection.hxx>
- #include <NXOpen/Session.hxx>
- #include <NXOpen/PDM_SoaConnectionHandle.hxx>
- #include <NXOpen/PDM_PdmSession.hxx>
- #include <NXOpen/PDM_PdmSearch.hxx>
- #include <NXOpen/PDM_PdmFile.hxx>
- #include <NXOpen/PDM_PdmNavigatorNode.hxx>
- #include <NXOpen/PDM_PdmPart.hxx>
- #include <NXOpen/PDM_PdmSearchManager.hxx>
- #include <NXOpen/PDM_SoaQuery.hxx>
- #include <NXOpen/PDM_SearchResult.hxx>
- #include <NXOpen/PrintPDFBuilder.hxx>
- #include <NXOpen/PlotManager.hxx>
- #include <NXOpen/Drawings_DrawingSheet.hxx>
- #include <NXOpen/NXObjectManager.hxx>
- // Std C++ Includes
- #include <iostream>
- #include <sstream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <tchar.h>
- #include <atlconv.h>
- #include <shellapi.h>
- #include <windows.h>
- #undef CreateDialog
- #pragma comment(lib,"shell32.lib")
- #define CREATION_DATE 1
- #define MODIFICATION_DATE 2
- #define MAX_UGMGR_NAME_LEN 1024
- using namespace NXOpen;
- using std::string;
- using std::exception;
- using std::stringstream;
- using std::endl;
- using std::cout;
- using std::cerr;
- NXOpen::ListingWindow *lw = NULL;
- NXOpen::NXMessageBox *mb = NULL;
- #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
- int report_error(char *file, int line, char *call, int code)
- {
- if (code){
- stringstream errmsg;
- errmsg << "Error " << code << " in " << file << " at line " << line << endl;
- errmsg << call << endl;
- cerr << errmsg.str();
- throw NXOpen::NXException::Create(code);
- }
- return(code);
- }
- void print(const NXString &);
- void print(const string &);
- void print(const char*);
- int invokePdmServer();
- int invokePdmServer()
- {
- int _errCode = 0;
- _errCode = UF_CALL(UF_UGMGR_initialize(0, NULL));
- char part_name[MAX_UGMGR_NAME_LEN + 1] = "000015200AA000000";
- int output_code = -1;
- char* date = NULL;
- _errCode = UF_CALL(UF_UGMGR_invoke_pdm_server(CREATION_DATE, part_name, &output_code, &date));
- print("\nAfter calling UF_UGMGR_invoke_pdm_server()\n");
- print("Part : " + string(part_name));
- print("creation date : " + string(date));
- print("output_code : " + std::to_string(output_code) + "\n\n");
- UF_free(date);
- date = NULL;
- UF_UGMGR_terminate();
- return _errCode;
- }
- extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
- {
- try
- {
- invokePdmServer();
- return;
- }
- catch (const NXException& e1)
- {
- UI::GetUI()->NXMessageBox()->Show("NXException", NXOpen::NXMessageBox::DialogTypeError, e1.Message());
- }
- catch (const exception& e2)
- {
- UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, e2.what());
- }
- catch (...)
- {
- UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, "Unknown Exception.");
- }
- }
- extern "C" DllExport int ufusr_ask_unload()
- {
- return (int)NXOpen::Session::LibraryUnloadOptionImmediately;// 调试用
- //return (int)NXOpen::Session::LibraryUnloadOptionAtTermination;// 程序发布用
- //return (int)NXOpen::Session::LibraryUnloadOptionExplicitly;
- }
- void print(const NXString &msg)
- {
- if (!lw->IsOpen()) lw->Open();
- lw->WriteLine(msg);
- }
- void print(const string &msg)
- {
- if (!lw->IsOpen()) lw->Open();
- lw->WriteLine(msg);
- }
- void print(const char * msg)
- {
- if (!lw->IsOpen()) lw->Open();
- lw->WriteLine(msg);
- }
复制代码Teamcenter Handler工程代码: - //======================================
- // libA2CustStudy_register_callbacks
- //======================================
- //=======================
- // libA2CustStudy.h
- //=======================
- #ifndef TCHANDLER_STUDY_H
- #define TCHANDLER_STUDY_H
- #pragma once
- #include <bom/bom.h>
- #include <ict/ict_userservice.h>
- #include <epm\epm_access_control.h>
- #include <epm\epm_task_template_itk.h>
- #include <epm\epm.h>
- #include <epm\epm_toolkit_iman_utils.h>
- #include <epm/epm_toolkit_tc_utils.h>
- #include <pie/sample_err.h>
- #include <tc/tc.h>
- #include <tc/iman.h>
- #include <tccore/custom.h>
- #include <tccore/aom_prop.h>
- #include <user_exits/user_exits.h>
- #include <tccore/workspaceobject.h>
- #include <tccore/aom.h>
- #include <tccore/item.h>
- #include <base_utils/Mem.h>
- #include "register_custom_user_service.h"
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- extern DLLAPI int libA2CustStudy_register_callbacks();
- int libA2CustStudy_invoke_pdm_server(int *decision, va_list args);
- #ifdef __cplusplus
- }
- #endif
- #endif
复制代码- //=======================
- // libA2CustStudy.cpp
- //=======================
- #include "libA2CustStudy.h"
- #define CUST_TCHANDLER_STUDY "libA2CustStudy"
- extern DLLAPI int libA2CustStudy_register_callbacks()
- {
- int stat = ITK_ok;
- stat = CUSTOM_register_exit(CUST_TCHANDLER_STUDY, "USER_invoke_pdm_server", (CUSTOM_EXIT_ftn_t)libA2CustStudy_invoke_pdm_server);
- stat == ITK_ok ? printf("(libA2CustStudy.dll)-函数libA2CustStudy_invoke_pdm_server返回值为ITK_ok,注册成功!!!\n") : printf("(libA2CustStudy.dll)-函数libA2CustStudy_invoke_pdm_server返回值不等于ITK_ok,注册失败!!!\n");
- return stat;
- }
复制代码
Teamcenter 零组件属性
NX信息框信息
|
|