Sub Main()
Dim oProgressbar As ProgressBar
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
Dim oSheet As Sheet
Dim sSheetName As String
Dim iSheetNumber As Integer
Dim i As Integer
'get PDF target folder path
oFolder = 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
If oPDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
'set global PDF options
oOptions.Value("All_Color_AS_Black") = iProperties.Value("Custom", "PDF_All Colors as Black")
oOptions.Value("Remove_Line_Weights") = iProperties.Value("Custom", "PDF_Remove Line Weights")
oOptions.Value("Vector_Resolution") = 400
Select Case Parameter("Print_Choice")
Case "Separate Drawings"
'Exports all sheets as separate PDFs
'Assumes each sheet has a unique name.
'Sheets with duplicate names will be overwritten and lost
oProgressbar = ThisApplication.CreateProgressBar(False, oDocument.Sheets.Count, "Exporting PDFs", True)
AddHandler oProgressbar.OnCancel, AddressOf OnCancel
i = 1
For Each oSheet In oDocument.Sheets
If UserWantsToCancel Then
oProgressbar.Close
Exit For
End If
Dim SheetSuffix As String = ""
If oSheet.Size = 9988 Then
sSheetName = oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(14))
SheetSuffix = oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(28))
Else
sSheetName = oSheet.TitleBlock.GetResultText(oSheet.TitleBlock.Definition.Sketch.TextBoxes.Item(18))
End If
If sSheetName = "" Then Continue For
oProgressbar.Message = "Exporting " & sSheetName & SheetSuffix & " Rev" & oSheet.Revision & ".pdf"
oProgressbar.UpdateProgress
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
oOptions.Value("Custom_Begin_Sheet") = i
oOptions.Value("Custom_End_Sheet") = i
oDataMedium.FileName = oFolder & "\" & sSheetName & SheetSuffix & " Rev" & oSheet.Revision & ".pdf"
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
i = i + 1
Next
oProgressbar.Close
End Select
End If
End Sub
Private Property UserClickedOnCancel() As Boolean = False
Function UserWantsToCancel()
If (UserClickedOnCancel) Then
MsgBox("Cancelling Export.")
Return True
End If
Return False
End Function
Sub OnCancel()
UserClickedOnCancel = True
End Sub
Thanks for replying,
I've inserted the code that is causing us the most headache, though it isn't just limited to this. I determined already that getting the result text from the sheets, as well as the code for the progress bar have no noticeable effect on performance. Unfortunately, the solution you offered of clearing the objects also had no effect on performance. The document I'm testing on has 97 sheets, and each sheet takes roughly 1min 30sec to export using the above code.