欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

PROE 二次开发(protoolkit):将 PRT 或 ASM 模型转换为 STEP、PS、IGES、CATIA 及其他格式。

最编程 2024-03-04 13:22:20
...

PROE强大的参数化建模能力在各种领域应用广泛。本文讨论三个函数:ProRasterFileWrite,ProIntf3DFileWrite和ProPDFExport

这三个函数的共同特点是导出模型,具体有所不同。ProRasterFileWrite导出图片;ProIntf3DFileWrite则侧重与各种三维图形格式的转换;ProPDFExport则把模型导出为PDF格式文件。

(1)ProRasterFileWrite

ProRasterFileWrite函数定义如下:

ProError ProRasterFileWrite (
  int window_id  
  /* (In)
  导出窗口ID,当前窗口用ProWindowCurrentGet获得
  */
  ProRasterDepth depth  
  /* (In)
  像素类型:PRORASTERDEPTH_8;PRORASTERDEPTH_24 
  */
  double width  
  /* (In)
  图片宽度多少 inches
  */
  double height  
  /* (In)
  图片宽度多少 inches
  */
  ProDotsPerInch dots_per_inch  
  /* (In)
  每个英寸多少像素PRORASTERDPI_100 = 100, PRORASTERDPI_200 = 200, PRORASTERDPI_300 = 300, PRORASTERDPI_400 = 400, PRORASTERDPI_500 = 500, PRORASTERDPI_600 = 600
  */
  ProRasterType type  
  /* (In)
  图形格式:PRORASTERTYPE_BMP, PRORASTERTYPE_TIFF, PRORASTERTYPE_EPS, PRORASTERTYPE_JPEG
  */
  ProPath output_file  
  /* (In)
  文件名称,包含扩展名
  */
)

这个函数用法很简单,就是把当前窗口打印出来,可以生成几种不同的图形格式: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可以将模型导出成如下格式:

 

 

Export Format
Pro/TOOLKIT Functions

Type Constant

STEP file (Standard for the Exchange of Product Model Data)

ProIntf3DFileWrite()

PRO_INTF_EXPORT_STEP

SET file (Standard for Exchange and Transfer)

ProIntf3DFileWrite()

PRO_INTF_EXPORT_SET

VDA file

ProIntf3DFileWrite()

PRO_INTF_EXPORT_VDA

IGES (3D) file

ProIntf3DFileWrite()

PRO_INTF_EXPORT_IGES

CATIA file

ProIntf3DFileWrite()

PRO_INTF_EXPORT_CATIA

CATIA (.model) file

ProIntf3DFileWrite()

PRO_INTF_EXPORT_
CATIA_MODEL

SAT file (ACIS format for Pro/ENGINEER)

ProIntf3DFileWrite()

PRO_INTF_EXPORT_SAT

NEUTRAL file (ASCII text)

ProIntf3DFileWrite()

PRO_INTF_EXPORT_
NEUTRAL

CADDS file

ProIntf3DFileWrite()

PRO_INTF_EXPORT_CADDS

CATIA (.session) file

ProIntf3DFileWrite()

PRO_INTF_EXPORT_CATIA_
SESSION

PDGS files

ProIntf3DFileWrite()

PRO_INTF_EXPORT_PDGS

Parasolid file

ProIntf3DFileWrite()

PRO_INTF_EXPORT_
PARASOLID

UG file

ProIntf3DFileWrite()

PRO_INTF_EXPORT_UG

函数定义如下:

ProError ProIntf3DFileWrite (
  ProSolid solid  
  /* (In)
  The solid model used for export.
  */
  ProIntf3DExportType file_type  
  /* (In)
  The type of output file to produce.
  */
  ProPath output_file  
  /* (In)
  The output file name to produce. Optionally, this includes the path for the file location. The filename should not include the file extension, this will be added automatically by Pro/ENGINEER.
  */
  ProOutputAssemblyConfiguration configuration  
  /* (In)
  Specifies the number and type of output files to produce. Users should check that this option is valid for the type of output specified in file_type by using the function ProOutputAssemblyConfigurationIsSupported(). If file_type == PRO_INTF_EXPORT_CADDS or PRO_INTF_EXPORT_NEUTRAL, this value is ignored by Pro/ENGINEER.
  */
  ProSelection reference_csys  
  /* (In)
  The reference coordinate system. If NULL, the system uses the default coordinate system. If file_type == PRO_INTF_EXPORT_CADDS or PRO_INTF_EXPORT_NEUTRAL, this should be NULL.
  */
  ProOutputBrepRepresentation brep_representation  
  /* (In)
  The options that specify the type of representation to create. Users should check that these options are valid for the type of output specified in file_type by using the function ProOutputBrepRepresentationIsSupported(). If file_type == PRO_INTF_EXPORT_CADDS or PRO_INTF_EXPORT_NEUTRAL, this should be NULL.
  */
  ProOutputInclusion inclusion  
  /* (In)
  The options for entity inclusion or exclusion in the output file(s). If file_type == PRO_INTF_EXPORT_CADDS or PRO_INTF_EXPORT_NEUTRAL, this should be NULL.
  */
  ProOutputLayerOptions layer_options  
  /* (In)
  The options that specify how layers are to be output. If file_type == PRO_INTF_EXPORT_CADDS or PRO_INTF_EXPORT_NEUTRAL, this should be NULL.
  */
 

几点注意事项:

参数ProIntf3DExportType定义导出类型,有下面几种:

typedef	enum 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;

请注意这个参数:ProOutputAssemblyConfiguration configuration
它定义了装配导出后的性质,可以将整个装配体定义为一个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是否对当前模型适应。ProOutputBrepRepresentation brep_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        );结束后释放内存:ProOutputBrepRepresentationFreeProOutputInclusion inclusion:规定一些辅助线,坐标系是否导出
用这个函数进行设置: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 或者 ASM
    ProMdlCurrentGet(&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 regardless
                                              of any of the modification flags 
                                              PRO_PDFOPT_ALLOW_* listed below */
    PRO_PDFOPT_RESTRICT_OPERATIONS,        /* Boolean, default FALSE
                                              set 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 TRUE
                                              allows visually impaired screen reader
                                              devices to extract data independent of
                                              RestrictOperationsMode */
} 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);