- Java锁的逻辑(结合对象头和ObjectMonitor)
- 还在用饼状图?来瞧瞧这些炫酷的百分比可视化新图形(附代码实现)⛵
- 自动注册实体类到EntityFrameworkCore上下文,并适配ABP及ABPVNext
- 基于Sklearn机器学习代码实战
该工程为在保存时执行开发的功能,函数入口点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::PrintPDFBuilder::ColorBlackOnWhite); 77 printPDFBuilder1-> SetWidths(NXOpen::PrintPDFBuilder::WidthCustomThreeWidths); 78 printPDFBuilder1->SetRasterImages( true ); 79 printPDFBuilder1-> SetImageResolution(NXOpen::PrintPDFBuilder::ImageResolutionOptionHigh); 80 printPDFBuilder1->SetAddWatermark( true ); 81 printPDFBuilder1-> SetWatermark(waterRemark.c_str()); 82 printPDFBuilder1-> SetAppend(appendStatus); 83 84 std::vector<NXOpen::NXObject *> sheets1( 1 ); 85 NXOpen::Drawings::DrawingSheet *drawingSheet1(dynamic_cast<NXOpen::Drawings::DrawingSheet *> (NXOpen::NXObjectManager::Get(sheetTAG))); 86 sheets1[ 0 ] = drawingSheet1; 87 printPDFBuilder1->SourceBuilder()-> SetSheets(sheets1); 88 printPDFBuilder1-> SetFilename(exportPath); 89 90 NXOpen::NXObject * nXObject1; 91 nXObject1 = printPDFBuilder1-> Commit(); 92 printPDFBuilder1-> Destroy(); 93 return 0 ; 94 } 95 catch ( const exception& e2){ 96 UI::GetUI()->NXMessageBox()->Show( " Exception " , NXOpen::NXMessageBox::DialogTypeError, e2.what()); 97 throw ; 98 } 99 } 100 101 int getSheetInfos() 102 { 103 // 获取显示部件及图纸信息 104 int _errCode = 0 ; 105 tag_t dispTAG = UF_PART_ask_display_part(); 106 char part_fspec[MAX_FSPEC_BUFSIZE] = { 0 }; 107 if (_errCode = UF_PART_ask_part_name(dispTAG, part_fspec) != 0 ) return _errCode; 108 109 std:: string strPartName(part_fspec); 110 transform(strPartName.begin(), strPartName.end(), strPartName.begin(), ::tolower); 111 if (strPartName.find( " dwg " ) == string ::npos) return - 1 ; 112 113 int num_draws = 0 ; 114 tag_t *drawTAGs = nullptr; 115 if (_errCode = UF_DRAW_ask_drawings(&num_draws, &drawTAGs) != 0 ) 116 return _errCode; 117 118 string export_path = strPartName.substr( 0 , strPartName.find_last_of( " . " )); 119 for ( int idx = 0 ; idx < num_draws; idx++ ){ 120 // 导出PDF 121 UF_DRAW_info_t drawInfos; 122 _errCode = UF_DRAW_ask_drawing_info(drawTAGs[ 0 ], & drawInfos); 123 double xDimension = drawInfos.size.custom_size[ 0 ]; 124 double yDimension = drawInfos.size.custom_size[ 1 ]; 125 _errCode = exportDwg2PDF(xDimension, yDimension, string ( " huangym1\r\n2023-03-25 " ), drawTAGs[idx], export_path + " .pdf " , false ); 126 string tempStr(export_path + " .pdf " ); 127 128 // 打开PDF 129 USES_CONVERSION; 130 const WCHAR * cLineChar = A2W(tempStr.c_str()); 131 132 SHELLEXECUTEINFO sei; 133 ZeroMemory(&sei, sizeof (SHELLEXECUTEINFO)); // 使用前最好清空 134 sei.cbSize = sizeof (SHELLEXECUTEINFO); // 管理员权限执行cmd,最基本的使用与 ShellExecute 类似 135 sei.lpFile = cLineChar; 136 sei.nShow = SW_SHOW; 137 sei.lpVerb = _T( " open " ); 138 BOOL bResult = ShellExecuteEx(& sei); 139 if (bResult) // 执行成功 140 { 141 if (sei.hProcess) // 指定 SEE_MASK_NOCLOSEPROCESS 并其成功执行,则 hProcess 将会返回执行成功的进程句柄 142 WaitForSingleObject(sei.hProcess, INFINITE); // 等待执行完毕 143 } 144 } 145 if (drawTAGs){ 146 UF_free(drawTAGs); 147 drawTAGs = nullptr; 148 } 149 return _errCode; 150 } 151 152 // ======================== 153 // 保存操作入口点函数 154 // ======================== 155 extern " C " DllExport void ufput() 156 { 157 try { 158 if (UF_initialize()) return ; 159 160 getSheetInfos(); 161 162 UF_terminate(); 163 } 164 catch ( const NXException& e1) 165 { 166 UI::GetUI()->NXMessageBox()->Show( " NXException " , NXOpen::NXMessageBox::DialogTypeError, e1.Message()); 167 } 168 catch ( const exception& e2) 169 { 170 UI::GetUI()->NXMessageBox()->Show( " Exception " , NXOpen::NXMessageBox::DialogTypeError, e2.what()); 171 } 172 catch (...) 173 { 174 UI::GetUI()->NXMessageBox()->Show( " Exception " , NXOpen::NXMessageBox::DialogTypeError, " Unknown Exception. " ); 175 } 176 }
。
GIF动图展示:
。
最后此篇关于NX二次开发:保存时导出PDF并打开的文章就讲到这里了,如果你想了解更多关于NX二次开发:保存时导出PDF并打开的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我开始学习 Oracle JavaSE 认证考试。 我创建了一个 IntelliJ Idea 项目来处理我的训练源代码。我想尽量减少 IntelliJ Idea 的帮助。 我只想使用:颜色语法、终端选
默认情况下,.DPR 和 .DPROJ 的文件扩展名描述是相同的,因此在资源管理器中打开具有相同基本名称的项目文件时,两个文件描述都会列为“Delphi 项目文件”,这提供了一个选择开发人员 - 要打
我目前正在从 android 网站了解 Navigation Drawer,我正在使用他们的示例 http://developer.android.com/training/implementing-
我需要帮助。 我在 A3:A500 列中有单词和数字 我需要改变他们的名字。 如果单元格包含单词“previ”,则如果单元格是数字,则将字母“p”放入新列中。如果它是一个词,那么不要放“p” ...就
我正在尝试编写一些 VBA,它允许按钮添加一个空行,保持相同的格式,就在 SUM 公式所在的行上方。 到目前为止,我实现了创建一个空行,但我不知道如何实现代码以让该新行继承相同的格式样式(包括边框和格
我在共享网络驱动器上有两个工作簿: 工作簿 A(表) 工作簿 B(数据透视表 - 连接到源工作簿 A) 我正在尝试,当打开 Workbook B 时,运行宏并执行以下操作: 取消保护工作簿 B 上的某
我正在开发一个需要在在线/离线模式下进行测试的应用程序,所以我想知道是否有任何方法可以打开/关闭 iPad 模拟器的互联网连接(不关闭我的 MAC 的互联网服务)。请帮忙 最佳答案 不,模拟器使用与您
我需要对目录的所有文件执行我的脚本(搜索)。以下是有效的方法。我只是问哪个最好。 (我需要格式的文件名:parsedchpt31_4.txt) 全局: my $parse_corpus; #(for
在我的代码中,我想有条件地执行一些操作: #ifdef DEBUG NSLog(@"I'm in debug mode"); #endif 我已配置“项目”->“编辑项目设置”->“构建”选项卡,以便
我编写了一个小程序来比较笔记本电脑的性能。为了使程序CPU更加密集,我用一些多线程代码(通过Parallel API实现)实现了Rabin-Karp模式匹配算法。 我注意到,当在关闭编译器优化标志的情
使用以下代码来关闭模态并打开第二个模态。总是遇到同样的问题可以关闭一个但不能打开第二个,或者如果我更改顺序我可以打开一个但不能关闭另一个。 (我想我已经尝试过101版本了)。如果有人能帮忙的话。
blue sky 默认情况下,当指针悬停时显示标题。 是否可以切换它,例如: $('#button').on('click', function(){ if (something) {turn
我正在编写一个简单的宏,它将打开、保存和关闭一个 Excel 文件(例如 myworkbook.xlsx),但我无法执行此操作。我的文件 myworkbook.xlsx 位于以下位置: C:\User
我正在加载两个 geoJson 层 - 出于测试目的,两个层都是相同的数据,但是是从两个不同的 json 文件中提取的。当我在图层 Controller 中打开和关闭图层时,图层的绘制顺序会发生变化。
我在我的设置 Activity 中发现,当用户单击 ToggleButton 时,它应该在整个应用程序中静音,但它不起作用。我在教程类中放入的 SoundPool onClick 按钮声音仍在 onC
我有一部双卡手机。如果我想打开飞行模式,两个 SIM 卡都会发生这种情况。 是否可以通过编程方式仅对一张SIM卡进行操作(用户可以选择两者之一)?我看到了here上的帖子,他们一直工作到 API 16
我目前正在开发一个带有一些 pipe() 和重定向的 C shell 程序。 我使用 dup2() stdout 和 stderr (1 & 2) 重定向。 当我用 int fd = open("te
Jquery: 有没有办法捕获浏览器打开“打开/另存为”对话框时触发的事件? Open/Save dialog example http://qpack.orcanos.com/helpcenter/
我知道你可以用 window.close 关闭 window.open 但还有其他方法吗?我有一个打开 facebook 连接的弹出窗口,我想在用户连接到 facebook 时关闭弹出窗口,然后刷新父
我搜索一个事件,如果不存在,则搜索一种方法来了解屏幕是否关闭(电源选项 - 控制面板 - 关闭显示设置)。 这些解决方案都不适合我。 所以要么我在某个地方错了,要么就是不合适。 How to get
我是一名优秀的程序员,十分优秀!