본문 바로가기
  • Welcome!
VBA, VB.NET For Creo

Creo Drawing 파일 PDF 변환 하기

by ToolBOX01 2022. 10. 11.
반응형

Drawing 파일을 opne 합니다.  여러개의 sheet 파일이 있으면 결합 하여 1개의 PDF로 변환 됩니다.

기존 동일한 PDF 파일 있으면 자동으로 덮어쓰기가 됩니다.

 

Sub Drawingpdfexport()

On Error GoTo RunError
     
    Dim asynconn As New pfcls.CCpfcAsyncConnection
    Dim conn As pfcls.IpfcAsyncConnection: Set conn = asynconn.Connect("", "", ".", 5)
    Dim oSession As pfcls.IpfcBaseSession: Set oSession = conn.session 'Get the current session
    Dim oModel As pfcls.IpfcModel: Set oModel = oSession.CurrentModel
    Dim oWindow As IpfcWindow: Set oWindow = oSession.GetModelWindow(oModel)
    
    'Activate the new window before printing (Good practice)
    oWindow.Activate

    Dim PDFExportInstrCreate As New CCpfcPDFExportInstructions
    Dim PDFExportInstr As IpfcPDFExportInstructions:  Set PDFExportInstr = PDFExportInstrCreate.Create
    Dim PDF_Options As New pfcls.CpfcPDFOptions

    ' Set Stroke All Fonts PDF Option
    Dim PDFOptionCreate_SAF As New CCpfcPDFOption
    Dim PDFOption_SAF As IpfcPDFOption: Set PDFOption_SAF = PDFOptionCreate_SAF.Create
    PDFOption_SAF.OptionType = EpfcPDFOptionType.EpfcPDFOPT_FONT_STROKE
    
    Dim newArg_SAF As New CMpfcArgument
    PDFOption_SAF.OptionValue = newArg_SAF.CreateIntArgValue(EpfcPDFFontStrokeMode.EpfcPDF_STROKE_ALL_FONTS)
    Call PDF_Options.Append(PDFOption_SAF)

    ' Set COLOR_DEPTH value (Set EpfcPDF_CD_MONO to have Black & White output)
    Dim PDFOptionCreate_CD As New CCpfcPDFOption
    Dim PDFOption_CD As IpfcPDFOption: Set PDFOption_CD = PDFOptionCreate_CD.Create
    PDFOption_CD.OptionType = EpfcPDFOptionType.EpfcPDFOPT_COLOR_DEPTH
    
    Dim newArg_CD As New CMpfcArgument
    PDFOption_CD.OptionValue = newArg_CD.CreateIntArgValue(EpfcPDFColorDepth.EpfcPDF_CD_MONO)
    Call PDF_Options.Append(PDFOption_CD)

    ' Set PDF EpfcPDFOPT_LAUNCH_VIEWER(Set FALSE Not to Launch Adobe reader)
    Dim PDFOptionCreate_LV As New CCpfcPDFOption
    Dim PDFOption_LV As IpfcPDFOption: Set PDFOption_LV = PDFOptionCreate_LV.Create
    PDFOption_LV.OptionType = EpfcPDFOptionType.EpfcPDFOPT_LAUNCH_VIEWER
    Dim newArg_LV As New CMpfcArgument
    PDFOption_LV.OptionValue = newArg_LV.CreateBoolArgValue(False)
    Call PDF_Options.Append(PDFOption_LV)

    'Set Output PDF File Name
    PDFExportInstr.FilePath = "C:\idt\pdf\" & oModel.FullName & ".pdf"
    PDFExportInstr.Options = PDF_Options
    Call oModel.Export(PDFExportInstr.FilePath, PDFExportInstr)
    
    
    MsgBox PDFExportInstr.FilePath & "변환을 완료 했습니다"
    
    'Disconnect with Pro/ENGINEER
    conn.Disconnect (2)
    'Cleanup
    Set asynconn = Nothing
    Set conn = Nothing
    Set oSession = Nothing
    Set oModel = Nothing
    
    
RunError:

    If Err.Number <> 0 Then
        MsgBox "Process Failed : Unknown error occurred." + Chr(13) + _
                "Error No: " + CStr(Err.Number) + Chr(13) + _
                "Error: " + Err.Description, vbCritical, "Error"

        If Not conn Is Nothing Then
            If conn.IsRunning Then
                conn.Disconnect (2)
            End If
        End If
    End If
    

End Sub

 

PDF 파일 저장 위치 입니다.

PDFExportInstr.FilePath = "C:\idt\pdf\" & oModel.FullName & ".pdf"