文章转载自唐康林NX二次开发论坛,原文出处: http://www.nxopen.cn/thread-126-1-1.html
刚才有同学问到这个问题,如果是用NXOpen来做,直接录制一下就可以了; 在UFUN里面没有直接的函数; 思路就是: 1、先将工程图转换为cgm 2、调用系统的cgm2pdf.exe工具,将上一步转换的cgm再转成PDF格式; 以下是我写的一个例子。大家可以拿一个工程图测试以下代码,最后会在C盘生成tkl.cgm与tkl.pdf两个文件。 #include <uf.h> #include <uf_draw.h> #include <uf_cgm.h> #include <windows.h> UF_initialize(); tag_t drawing_tag = NULL_TAG; UF_DRAW_ask_current_drawing(&drawing_tag); if (drawing_tag != NULL_TAG) { UF_CGM_export_options_t export_options; UF_CGM_ask_default_export_options(&export_options); //UF_CGM_ask_session_export_options(&export_options);//用这个函数也可以初始化 export_options.reason = UF_CGM_pdf_reason; UF_CGM_set_session_export_options(&export_options); char outFilePath[UF_CFI_MAX_FILE_NAME_BUFSIZE] = "c:\\tkl.cgm"; UF_CGM_export_cgm(drawing_tag, &export_options, outFilePath); //导出成CGM文件 //将CGM转换成PDF char outPdfFilePath[UF_CFI_MAX_FILE_NAME_BUFSIZE] = "c:\\tkl.pdf"; NXOpen::NXString nxbasedir = theSession->GetEnvironmentVariableValue("UGII_BASE_DIR");//获取NX主目录 std::ostringstream tempstring; tempstring << nxbasedir.GetLocaleText() << "\\NXPLOT\\bin\\pdf\\cgm2pdf.exe " << outFilePath << " " << outPdfFilePath; std::string covertvalule = tempstring.str(); WinExec(covertvalule.c_str(), SW_HIDE); //打开PDF转换器,并转换 tempstring.str(""); tempstring.clear(); } UF_terminate();
文章来源: https://blog.csdn.net/lu1287580078/article/details/89890352