该工程为在保存时执行开发的功能,函数入口点ufput。其他还有新建、打开、另存等都可以加入开发的操作,具体看UF_EXIT下的介绍。
用户出口是一个可选特性,允许你在NX中某些预定义的位置(或出口)自动运行Open C API程序。如果你进入其中一个出口,NX会检查你是否定义了指向Open C API程序位置的指针。如果定义了指针,NX将运行Open C API程序。指针是一个环境变量。
注意:
一定要设置环境变量指向自己生成的DLL。例如:USER_FILE=E:\workspace\Infore\tcnx_project\application\tcnx_project.dll
1 // Mandatory UF Includes 2 #include <uf.h> 3 #include <uf_object_types.h> 4 #include <uf_draw.h> 5 #include <uf_part.h> 6 7 // Internal+External Includes 8 #include <NXOpen/Annotations.hxx> 9 #include <NXOpen/Assemblies_Component.hxx> 10 #include <NXOpen/Assemblies_ComponentAssembly.hxx> 11 #include <NXOpen/Body.hxx> 12 #include <NXOpen/BodyCollection.hxx> 13 #include <NXOpen/Face.hxx> 14 #include <NXOpen/Line.hxx> 15 #include <NXOpen/NXException.hxx> 16 #include <NXOpen/NXObject.hxx> 17 #include <NXOpen/Part.hxx> 18 #include <NXOpen/PartCollection.hxx> 19 #include <NXOpen/Session.hxx> 20 21 #include <NXOpen/PrintPDFBuilder.hxx> 22 #include <NXOpen/PlotManager.hxx> 23 #include <NXOpen/Drawings_DrawingSheet.hxx> 24 #include <NXOpen/NXObjectManager.hxx> 25 26 // Std C++ Includes 27 #include <iostream> 28 #include <sstream> 29 #include <vector> 30 #include <string> 31 #include <algorithm> 32 #include <tchar.h> 33 #include <atlconv.h> 34 #include <shellapi.h> 35 36 #include <windows.h> 37 #undef CreateDialog 38 #pragma comment(lib,"shell32.lib") 39 40 using namespace NXOpen; 41 using std::string; 42 using std::exception; 43 using std::stringstream; 44 using std::endl; 45 using std::cout; 46 using std::cerr; 47 48 49 //------------------------------------------------------------------------------ 50 // Unload Handler 51 //------------------------------------------------------------------------------ 52 extern "C" DllExport int ufusr_ask_unload() 53 { 54 return (int)NXOpen::Session::LibraryUnloadOptionImmediately;// 调试用 55 //return (int)NXOpen::Session::LibraryUnloadOptionAtTermination;// 程序发布用 56 //return (int)NXOpen::Session::LibraryUnloadOptionExplicitly; 57 } 58 59 int exportDwg2PDF(double &xDimension, double &yDimension, std::string &waterRemark, tag_t &sheetTAG, std::string &exportPath, bool appendStatus) 60 { 61 try{ 62 if (xDimension < 200 || yDimension < 200 || sheetTAG == NULL_TAG || exportPath.empty() == true) 63 return -1; 64 65 NXOpen::Session *theSession = NXOpen::Session::GetSession(); 66 NXOpen::Part *workPart(theSession->Parts()->Work()); 67 NXOpen::Part *displayPart(theSession->Parts()->Display()); 68 NXOpen::PrintPDFBuilder *printPDFBuilder1; 69 printPDFBuilder1 = workPart->PlotManager()->CreatePrintPdfbuilder(); 70 71 printPDFBuilder1->SetScale(1.0); 72 printPDFBuilder1->SetSize(NXOpen::PrintPDFBuilder::SizeOptionScaleFactor); 73 printPDFBuilder1->SetOutputText(NXOpen::PrintPDFBuilder::OutputTextOptionPolylines); 74 printPDFBuilder1->SetXDimension(xDimension); 75 printPDFBuilder1->SetYDimension(yDimension); 76 printPDFBuilder1->SetColors(NXOpen::Print