Hi @nurinadlina695. I am not sure what all of your unique needs may be in this case, but give the following iLogic rule a try. I tried to include lots of 'comments' within the code, to help guide you through what each line of code is trying to do. If you have any questions, or it is not working as planned, just let us know.
Sub Main
'get the current document, then try to Cast its Type to the DrawingDocument Type
'if that fails, it will not throw an error, but will not set a value to the variable
Dim oDDoc As Inventor.DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
'if the variable did not get a value, then exit rule
If oDDoc Is Nothing Then Return
'get the PDF Translator Add-in
Dim oPDFAddin As Inventor.TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById( _
"{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
'Create the variables needed by the Translator Add-in
Dim oTO As Inventor.TransientObjects = ThisApplication.TransientObjects
Dim oContext As Inventor.TranslationContext = oTO.CreateTranslationContext()
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As Inventor.NameValueMap = oTO.CreateNameValueMap()
Dim oDataMedium As Inventor.DataMedium = oTO.CreateDataMedium()
'The following If-Then statement sets the values of available Options.
If oPDFAddin.HasSaveCopyAsOptions(oDDoc, oContext, oOptions) Then
oOptions.Value("Publish_All_Sheets") = 0 ' 0 = False, 1 = True
oOptions.Value("Sheet_Range") = PrintRangeEnum.kPrintCurrentSheet
oOptions.Value("Launch_Viewer") = 0 ' 0 = False, 1 = True
oOptions.Value("All_Color_AS_Black") = 0 ' 0 = False, 1 = True
oOptions.Value("Vector_Resolution") = 720 '150, 200, 400, 600, 720, 1200, 2400, 4800 ' DPI
oOptions.Value("Remove_Line_Weights") = 0 ' 0 = False, 1 = True
End If
'get static parts of new file name (not sheet depentant)
'this gets full path, without file name (does not include "\" character at end)
Dim sPath As String = System.IO.Path.GetDirectoryName(oDDoc.FullFileName)
'this gets just the file name, without any path, and without file extension
Dim sName As String = System.IO.Path.GetFileNameWithoutExtension(oDDoc.FullFileName)
'this just gets the directory separator character
Dim cDirChr As Char = System.IO.Path.DirectorySeparatorChar
'record originally 'active' sheet
Dim oASheet As Inventor.Sheet = oDDoc.ActiveSheet
'<<<< Start loop for each sheet - file name includes sheet name >>>>
For Each oSheet As Inventor.Sheet In oDDoc.Sheets
'activate this Sheet in the drawing
oSheet.Activate()
'extract just the index number of this Sheet
Dim sSheetNumber As String = oSheet.Name.Split(":")(1) 'get the digit(s) after the ":"
'same path and file name as drawing, but with .pdf file extension
Dim sNewFileName As String = sPath & cDirChr & sName & " Sheet " & sSheetNumber & ".pdf"
'Check to see if this PDF already exists
If System.IO.File.Exists(sNewFileName) = True Then
'this file already exists, so ask user if they want to overwrite it
Dim oAnswer As MsgBoxResult = MsgBox("A PDF file with this name already exists." _
& vbCrLf & "Do you want to overwrite it with this new one?", _
vbYesNo + vbQuestion + vbDefaultButton2, "PDF ALREADY EXISTS")
'if they do not want to overwrite it, then skip this Sheet
If oAnswer = MsgBoxResult.No Then Continue For
End If
'set new PDF full file name
oDataMedium.FileName = sNewFileName
'Publish PDF
oPDFAddin.SaveCopyAs(oDDoc, oContext, oOptions, oDataMedium)
Next
oASheet.Activate()
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)