Printing Pdfs

Printing Pdfs

alanrichardson
Advocate Advocate
543 Views
2 Replies
Message 1 of 3

Printing Pdfs

alanrichardson
Advocate
Advocate
I'm currently using this code to print PDF files (thanks to numerous people in this community, for which I'm very grateful)

However I'd like to know . . . is it possible via iLogic to replace the default folder "F:\TEMP" and let the user navigate to
a folder of their choosing?

Thanks,




'------start of iLogic: Print PDF with Rev ------- oPath = ThisDoc.Path oFileName = ThisDoc.FileName(False) 'without extension oRevNum = iProperties.Value("Project", "Revision Number") oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _ ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oDocument = ThisApplication.ActiveDocument oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oDataMedium = ThisApplication.TransientObjects.CreateDataMedium If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'oOptions.Value("Custom_Begin_Sheet") = 2 'oOptions.Value("Custom_End_Sheet") = 4 End If 'get PDF target folder path oFolder = "F:\TEMP\" 'oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF" 'Check for the PDF folder and create it if it does not exist If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & oFileName & _ "-iss" & oRevNum & ".pdf" 'Publish document oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) '------end of iLogic-------
-----------------------------------------
Inventor 2020, Windows 10
0 Likes
Accepted solutions (1)
544 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Hi.

 

I found this iLogic code some time ago, written by Luke Davenport. It does what u want, you may have to change som things to fit your needs.

 

 

' This is an example iLogic rule by Luke Davenport on Cadline Community' It creates a 'folder browser dialog' to allow user to pick a directory location' This selected directory location is then used for a generic PDF export operation' Please modify to suit your requirements....

Imports System.Windows.Forms

    
' Get current location of this file
Dim ExportPath As String = ThisDoc.Path

' Check that this file has been saved and actually exists on disk
If String.IsNullOrEmpty(ExportPath) Then
    MsgBox("This file has not yet been saved and doesn't exist on disk! - please save it first",64, "Cadline iLogic")
Return
End If

' Define folder browse dialog
Dim Dialog = New FolderBrowserDialog()

' Set options for folder browser dialog
Dialog.SelectedPath = ExportPath
Dialog.ShowNewFolderButton = True
Dialog.Description = "Cadline - Choose Folder for Export..."

' Show dialog box
If DialogResult.OK = Dialog.ShowDialog() Then
    ' User clicked 'ok' on dialog box - capture the export path
    ExportPath = Dialog.SelectedPath & "\"
    
Else
    ' User clicked 'cancel' on dialog box - exit
    Return
End If

oRevNum = iProperties.Value("Project", "Revision Number")
oFileName = iProperties.Value("Project", "Part Number") 'without extension
If oRevNum = Nothing Then
' Define the filename of the file to be exported - in this case it is a PDF file extension
ExportFilename =  oFileName &  ".pdf"
Else
ExportFilename =  oFileName &  "-" & oRevNum & ".pdf"
End If

' Do export operation (using save as)
Try
    ThisDoc.Document.SaveAs(ExportPath & ExportFilename, True)
Catch
    MsgBox("File export failed...", 64, "Cadline iLogic")
End Try

' Ask user if they want to open (launch) the file we just exported...
If MsgBox("File exported: " & _
        ExportPath & ExportFilename & vbLf & vbLf & _
        "Do you want to open the PDF Now?", 36, "Cadline iLogic - File Exported") = 6 Then
    ' User says yes...launch exported file
    ThisDoc.Launch(ExportPath & ExportFilename)
End If

 

Message 3 of 3

alanrichardson
Advocate
Advocate
Accepted solution

Thanks for the ilogic code . . . it appears to have the parts I'm looking for.

 

Regards

 

Alan

-----------------------------------------
Inventor 2020, Windows 10
0 Likes