Export multiple sheets to separate PDF's with choosing sheets

Export multiple sheets to separate PDF's with choosing sheets

Anonymous
Not applicable
5,560 Views
27 Replies
Message 1 of 28

Export multiple sheets to separate PDF's with choosing sheets

Anonymous
Not applicable

Hi everyone

I have iLogic which export multiple sheets from idw to PDF's. This iLogic works excellent but problem is that it export all sheets from idw. Sometimes I need only 10 sheets from 30. Have anyone idea how to change iLogic to get possibility to choose few sheets from bulk, for example sheet 1, 3, 5 and 20 to 30? Thanks a lot for help in advance, Greg.

 

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
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

'Define the drawing
Dim oDrawing As DrawingDocument
oDrawing = ThisDoc.Document

Dim oSheet As Sheet
Dim lPos As Long
Dim rPos As Long
Dim sLen As Long
Dim sSheetName As String
Dim iSheetNumber As Integer

'step through each drawing sheet
For Each oSheet In oDrawing.Sheets

	'find the seperator in the sheet name:number
	lPos = InStr(oSheet.Name, ":")
	'find the number of characters in the sheet name
	sLen = Len(oSheet.Name)
	'find the sheet name
	sSheetName = Left(oSheet.Name, lPos -1)
	'find the sheet number
	iSheetNumber = Right(oSheet.Name, sLen -lPos)

	 
	oOptions.Value("All_Color_AS_Black") = 0
	oOptions.Value("Remove_Line_Weights") = 0
	oOptions.Value("Vector_Resolution") = 400
	oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentSheet 
	 

	'get PDF target folder path
	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 & "\" & sSheetName & " " & iSheetNumber  & ".pdf"
	oSheet.Activate
	'Publish document
	oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

Next

 

Accepted solutions (2)
5,561 Views
27 Replies
Replies (27)
Message 21 of 28

jolantavoigt9563
Explorer
Explorer

jolantavoigt9563_0-1675432130324.png

This one

0 Likes
Message 22 of 28

WCrihfield
Mentor
Mentor

@jolantavoigt9563 OK.  That appears to be the original code that @Anonymous first posted at the start of this topic.  That version of the code did not yet include specific sheet selection yet, so I assume that you simply want every sheet exported as a separate PDF, to the same location as the drawing file, and want to keep the sheet name & number as the name of each PDF.  Are you sure you do not want the drawing's original file name included in the PDF file's name, before the sheet name & number?  I will include a line that will include the drawing file's name in there, but keep that line commented out, just in case you may want to use that line instead of the line without it later.  I hope this is what you were looking for.

Dim oDrawing As DrawingDocument = ThisDoc.Document
Dim sPath As String = ThisDoc.Path
Dim sName As String = ThisDoc.FileName(False)
Dim oPDFAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism 
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
'these can be set once, before the loop, instead of each time within the loop
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentSheet 
Dim OriginalActiveSheet As Sheet = oDrawing.ActiveSheet
Dim sSheetName As String
Dim iSheetNumber As Integer

'step through each drawing sheet
For Each oSheet As Sheet In oDrawing.Sheets
	oSheet.Activate
	sSheetName = oSheet.Name.Split(":")(0)
	iSheetNumber = oSheet.Name.Split(":")(1)
	'Set the PDF target file name
	oDataMedium.FileName = sPath & "\" & sSheetName & " " & iSheetNumber & ".pdf"
	'oDataMedium.FileName = sPath & "\" & sName & " " & sSheetName & " " & iSheetNumber  & ".pdf"
	'Publish document
	oPDFAddIn.SaveCopyAs(oDrawing, oContext, oOptions, oDataMedium)
Next
OriginalActiveSheet.Activate

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

EESignature

(Not an Autodesk Employee)

Message 23 of 28

jolantavoigt9563
Explorer
Explorer

Yes, I wanted to export all sheets, thank you for your assistance.

0 Likes
Message 24 of 28

jolantavoigt9563
Explorer
Explorer

I'm very new to interacting in this forum, in any forum for that matter, I have always read thru many but never interacted. I have read your profile and we have a lot in common as far as CNC programming and Design engineering, I definitely would appreciate a mentor with your knowledge, is there such a thing in the Autodesk forum as adding someone to follow or add as favorites? Or maybe connect on LinkedIn?

0 Likes
Message 25 of 28

thy_inventorAL62J
Community Visitor
Community Visitor

Hi Guys,

 

I am sorry to ask, but I would like the exported pdf's to be named: filename-sheetname-sheetnumber.dpf

 

Right now the nameoutput is sheetname-sheetnumber.pdf

 

Is it possible?

 

🙂

 

Best regards Morten

0 Likes
Message 26 of 28

WCrihfield
Mentor
Mentor

Hi @thy_inventorAL62J.  Yes, that is possible.  In fact, that capability was already built into that last code I posted above, but that specific line of code, near the end of the code, was commented out (the line of code started with an apostrophe character).  If you remove the apostrophe (') from the start of that line, and add an apostrophe to the start of the line of code just before that one (or just delete the line of code just before that one), that should make the code work the way you want it to.  However, I slightly modified the code above to meet your needs and have posted the result within the attached text file.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 27 of 28

M_Santi
Enthusiast
Enthusiast

What would I need to change on the codes to remove the sheet number when creating the pdf.

I would get something like this:

8047F-X 1

8048F-X 2

8049F-X 3

0 Likes
Message 28 of 28

WCrihfield
Mentor
Mentor

Hi @M_Santi.  Your question is not very clear.  When you say "on the codes", which variation of code do you mean?  There has been several versions /  variations of codes posted within this long discussion so far.

 

Maybe a better question for me to ask you is...what do you want the code to do?  When you answer that question, please be as detailed and specific as you can possibly be.

  • Do you want to export all sheets of active drawing to one, multi-page PDF file?
  • Do you want to export each sheet of the active drawing to individual, single page PDF files?
  • Do you only want to export specific sheets within the active multi-sheet drawing to a single multi-page PDF file?
  • Do you only want to export specific sheets within the active multi-sheet drawing to individual, single page PDF files?
  • How do you intend to specify which sheets of the drawing to export?
  • Where should the PDF files be created?
  • How should each PDF file be named?
  • What settings should be used when exporting each PDF file?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes