Message 1 of 7

Not applicable
05-04-2016
04:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
With the help of the comunity I was able to piece together a custom code that print pdf files. I have attached the code below of what I have. My code currently spits out Page/Sheet 1 to 10. What I want to do is give the user the option to choose which sheet they want to export, instead of all of them. Eg. I want to print only page 2 to 5 or just page 1. Is there any code or example that I can add to my code that will have a pop-up window where the user inputs what sheets he wants?
I need to change the these lines to something else that will enable the option I want:
oOptions.Value("Custom_Begin_Sheet") = 1 oOptions.Value("Custom_End_Sheet") = 10
'iLogic rule to export PDF from Inventor Drawings 'By Fazlur Rahaman 'May 5, 2016 Imports System.Windows.Forms 'query user '------start of iLogic------- question = MessageBox.Show("You want to create PDF of this file?", "Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question) 'set condition based on answer If question = vbYes Then ' 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, "PDF EXPORT!") 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 = "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 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 'Formate PDF Setting If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 4800 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'Number of pages to be published oOptions.Value("Custom_Begin_Sheet") = 1 oOptions.Value("Custom_End_Sheet") = 10 End If 'get PDF target folder path oFolder = ExportPath If iProperties.Value("Project", "Revision Number") >= "1" Then 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & oFileName & _ " R" & oRevNum & ".pdf" Else 'Set the destination file name oDataMedium.FileName = oFolder & "\" & oFileName & _ " R" & oRevNum & ".pdf" End If Else Return End If On Error Goto handlePDFLock 'Publish document oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) '--------------------------------------------------?--------------------------------------------------?---------------- 'Option to the user if they want to open the file question2 = MessageBox.Show("Open PDF file?", "Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question) If question2 = vbYes Then ThisDoc.Launch(oDataMedium.FileName) End If Exit Sub handlePDFLock:MessageBox.Show("PDF not created, most likely someone else has it open.", "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!") 'Resume Next
Solved! Go to Solution.