PROE二次開發(protoolkit):把PRT或者ASM模型轉換成STEP,PS,IGES,CATIA等等格式


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
        );
結束后釋放內存:ProOutputBrepRepresentationFree

ProOutputInclusion 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>
主要函數有這么幾個:

 

主要的屬性對象如下:

 

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);

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM