PROE强大的参数化建模能力在各种领域应用广泛。本文讨论三个函数:ProRasterFileWrite,ProIntf3DFileWrite和ProPDFExport
这三个函数的共同特点是导出模型,具体有所不同。ProRasterFileWrite导出图片;ProIntf3DFileWrite则侧重与各种三维图形格式的转换;ProPDFExport则把模型导出为PDF格式文件。
(1)ProRasterFileWrite
ProRasterFileWrite函数定义如下:
这个函数用法很简单,就是把当前窗口打印出来,可以生成几种不同的图形格式:PRORASTERTYPE_BMP, PRORASTERTYPE_TIFF, PRORASTERTYPE_EPS, PRORASTERTYPE_JPEG。当然也可以用-1来代表当前窗口ID。
int id;ProWindowCurrentGet(&id);ProRasterFileWrite(id,PRORASTERDEPTH_24,100,100,PRORASTERDPI_100,PRORASTERTYPE_JPEG,L"out.jpeg");或者ProRasterFileWrite(-1,PRORASTERDEPTH_24,100,100,PRORASTERDPI_100,PRORASTERTYPE_JPEG,L"out2.jpeg");
当然也可以根据模型handle来获取窗口:ProMdlWindowGet ( ProMdl mdl, int* window_id );
(2)ProIntf3DFileWrite
ProIntf3DFileWrite可以将模型导出成如下格式:
函数定义如下:
几点注意事项:
参数ProIntf3DExportType定义导出类型,有下面几种:
typedefenum pro_intf3d_export_type {PRO_INTF_EXPORT_STEP = 1,PRO_INTF_EXPORT_SET,PRO_INTF_EXPORT_VDA,PRO_INTF_EXPORT_IGES,PRO_INTF_EXPORT_CATIA,PRO_INTF_EXPORT_CATIA_MODEL,PRO_INTF_EXPORT_SAT,PRO_INTF_EXPORT_NEUTRAL,PRO_INTF_EXPORT_CADDS,PRO_INTF_EXPORT_CATIA_SESSION, /* Not currently supported; *//* reserved for future use. */PRO_INTF_EXPORT_PDGS, /* Not currently supported; *//* reserved for future use. */PRO_INTF_EXPORT_PARASOLID,PRO_INTF_EXPORT_UG,PRO_INTF_EXPORT_RESERVED,PRO_INTF_EXPORT_CATIA_PART,PRO_INTF_EXPORT_CATIA_PRODUCT} ProIntf3DExportType;
请注意这个参数:ProOutputAssemblyConfigurationconfiguration
它定义了装配导出后的性质,可以将整个装配体定义为一个PART,或者将装配所包含的所有部件逐一导出,详细解释:PRO_OUTPUT_ASSEMBLY_FLAT_FILE:表示将ASM当作PART处理,导出后整个ASM模型合并成一个PART。PRO_OUTPUT_ASSEMBLY_SINGLE_FILE:将ASM文件导出,引用其其现有组成部件。PRO_OUTPUT_ASSEMBLY_MULTI_FILES:将ASM文件导出,将其现有组成部件也一起逐个导出。PRO_OUTPUT_ASSEMBLY_PARTS
可以用ProOutputAssemblyConfigurationIsSupported判断ProOutputAssemblyConfiguration是否对当前模型适应。
ProOutputBrepRepresentationbrep_representation:如何表示导出的几何体,当作线,面或者体
先用ProOutputBrepRepresentationAlloc制造一个ProOutputBrepRepresentation
然后调用函数进行设置:
ProOutputBrepRepresentationFlagsSet(rep,
PRO_B_FALSE,//ProBoolean as_wireframe,
PRO_B_FALSE,//ProBoolean as_surfaces,
PRO_B_TRUE,//ProBoolean as_solid,
PRO_B_FALSE//ProBoolean as_quilts
);
结束后释放内存:ProOutputBrepRepresentationFree
ProOutputInclusioninclusion:规定一些辅助线,坐标系是否导出
用这个函数进行设置:ProOutputInclusionFlagsSet(lnc,PRO_B_TRUE,//ProBoolean include_datums,PRO_B_FALSE,//ProBoolean include_blanked,PRO_B_FALSE//ProBoolean include_facetted );
最好放掉内存:ProOutputInclusionFree
一个简单的例子如下:将当前的PRT或者ASM导出为.ps(PARASOLID)格式。
ProMdl mdl;ProOutputBrepRepresentation rep;ProOutputBrepRepresentationAlloc(&rep);ProOutputBrepRepresentationFlagsSet(rep,PRO_B_FALSE,//ProBoolean as_wireframe,PRO_B_FALSE,//ProBoolean as_surfaces,PRO_B_TRUE,//ProBoolean as_solid,PRO_B_FALSE//ProBoolean as_quilts );ProBoolean pb;//检查输出选项是否支持ProError er=ProOutputBrepRepresentationIsSupported(PRO_INTF_EXPORT_PARASOLID,rep,&pb);if (er!=PRO_TK_NO_ERROR||!pb){AfxMessageBox("Not Support!");return;}ProOutputInclusion lnc;ProOutputInclusionAlloc(&lnc);ProOutputInclusionFlagsSet(lnc,PRO_B_TRUE,//ProBoolean include_datums,PRO_B_FALSE,//ProBoolean include_blanked,PRO_B_FALSE//ProBoolean include_facetted );ProOutputLayerOptions lop;ProOutputLayerOptionsAlloc(&lop);ProOutputLayerOptionsAutoidSet(lop,PRO_B_FALSE//auto_ids );//当前PRT 或者 ASMProMdlCurrentGet(&mdl);if (!mdl){AfxMessageBox("no prt or asm avaiable");return;}
//导出ProIntf3DFileWrite((ProSolid)mdl,PRO_INTF_EXPORT_PARASOLID,//导出ps格式L"new_ps_name",//不要带后缀名,会自动加上去PRO_OUTPUT_ASSEMBLY_FLAT_FILE,//将ASM当作一个PART处理导出 NULL,rep,lnc,lop);ProOutputBrepRepresentationFree(rep);ProOutputInclusionFree(lnc);ProOutputLayerOptionsFree(lop);
模型文件:
导出PS格式后:
(3)导出PDF文件
需要包含头文件#include <ProPDF.h>
主要函数有这么几个:
ProPDFoptionsIntpropertySet():设置int型参数值
ProPDFoptionsAlloc():产生一个ProPDFOptions对象,后面的属性设置和导出都需要ProPDFOptions作为输入
ProPDFoptionsBoolpropertySet():设置bool值ProPDFoptionsStringpropertySet():设置string值ProPDFExport():导出PDF文件ProPDFoptionsFree():释放ProPDFOptions对象
主要的属性对象如下:
typedef enum{PRO_PDFOPT_FONT_STROKE,/* Enum, ProPDFFontStrokeMode, default PRO_PDF_USE_TRUETYPE_FONTS */PRO_PDFOPT_COLOR_DEPTH,/* Enum, ProPDFColorDepth,default PRO_PDF_CD_COLOR */PRO_PDFOPT_HIDDENLINE_MODE, /* Enum, ProPDFHiddenLineMode,default PRO_PDF_HLM_DASHED */PRO_PDFOPT_SEARCHABLE_TEXT, /* Boolean, default TRUE */PRO_PDFOPT_RASTER_DPI, /* Int, Range 100 - 600, default 300 */PRO_PDFOPT_LAUNCH_VIEWER, /* Boolean, default TRUE */PRO_PDFOPT_LAYER_MODE, /* Enum, ProPDFLayerMode,default PRO_PDF_LAYERS_ALL */PRO_PDFOPT_PARAM_MODE, /* Enum, ProPDFParamMode,default PRO_PDF_PARAMS_ALL */PRO_PDFOPT_HYPERLINKS, /* Boolean, default TRUE */PRO_PDFOPT_BOOKMARK_ZONES, /* Boolean, default TRUE */PRO_PDFOPT_BOOKMARK_VIEWS, /* Boolean, default TRUE */PRO_PDFOPT_BOOKMARK_SHEETS, /* Boolean, default TRUE */PRO_PDFOPT_BOOKMARK_FLAG_NOTES, /* Boolean, default TRUE */PRO_PDFOPT_TITLE, /* String, default "" */PRO_PDFOPT_AUTHOR, /* String, default <current user name> */PRO_PDFOPT_SUBJECT,/* String, default "" */PRO_PDFOPT_KEYWORDS, /* String, default "" */PRO_PDFOPT_PASSWORD_TO_OPEN, /* String, default NULL, which means that the document may be opened by anyone */PRO_PDFOPT_MASTER_PASSWORD, /* String, default NULL,which means that anyone may perform any change regardlessof any of the modification flags PRO_PDFOPT_ALLOW_* listed below */PRO_PDFOPT_RESTRICT_OPERATIONS, /* Boolean, default FALSEset to TRUE to use PRO_PDFOPT_ALLOW_*to use ProPDFRestrictOperationsMode */PRO_PDFOPT_ALLOW_PRINTING, /* Boolean, default TRUE */PRO_PDFOPT_ALLOW_PRINTING_MODE, /* Enum, ProPDFPrintingMode,default PRO_PDF_PRINTING_HIGH_RES */PRO_PDFOPT_ALLOW_MODE, /* Enum, ProPDFRestrictOperationsMode,default PRO_PDF_RESTRICT_NONE */PRO_PDFOPT_ALLOW_COPYING, /* Boolean, default TRUE */PRO_PDFOPT_ALLOW_ACCESSIBILITY /* Boolean, default TRUEallows visually impaired screen readerdevices to extract data independent ofRestrictOperationsMode */} ProPDFOptionType;
示例代码如下:
ProPDFOptions ops;ProPDFoptionsAlloc(&ops);//use ProPDFoptionsBoolpropertySet() and ProPDFoptionsStringpropertySet()//to set property//............... ProMdl mdl;ProMdlCurrentGet(&mdl);if (!mdl){AfxMessageBox("no prt or asm avaiable");return;}ProPDFExport(mdl,L"obj.pdf",ops);ProPDFoptionsFree(ops);