I want to run an iLogic script to open all my .idw's in a folder and export them as .pdf

I want to run an iLogic script to open all my .idw's in a folder and export them as .pdf

drafting3QE6L
Contributor Contributor
1,670 Views
5 Replies
Message 1 of 6

I want to run an iLogic script to open all my .idw's in a folder and export them as .pdf

drafting3QE6L
Contributor
Contributor

I have found a script that will open all .ipt's one by one and export an image of the iso view to a set folder.

 

Source: https://forums.autodesk.com/t5/inventor-customization/batch-export-images/td-p/5370275

 

Thing is, I want to tweak the code such that instead of opening parts, I want it to open Drawings, and instead of exporting a picture, I want a pdf. Would this be possible, or is this a bigger rabbit hole than I expected?

 

Thank you for any help,

James

Accepted solutions (1)
1,671 Views
5 Replies
Replies (5)
Message 2 of 6

Chancellor.Kurre
Advocate
Advocate

You could look into the Inventor task scheduler and try to print to a PDF printer. Haven't dug into it much for that, but it should work.

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor

Hi @drafting3QE6L .  This definitely sounds doable with an iLogic rule, but once started the task of opening every drawing file in a directory and exporting them will likely take a long time, depending on the scope (how many).  Because of how long the task may take though, this type of job is probably better suited for an Addin, or as @Chancellor.Kurre  suggested, using the Inventor Task Scheduler and printing them to file using a PDF printer.  I have written similar rule's before that target all documents of a certain type within a directory, open them, do something to them (like 'inject' iProperties), then close them, but I haven't created one for that specific task yet.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

drafting3QE6L
Contributor
Contributor

@WCrihfield The good news is that timeframe will not be an issue. We are changing systems at work and once the transition is done, any edits to drawings will be exported then and there as pdf. I found a different block of code that will execute an "export as pdf" command, so right now it is a matter of inserting the code in a way that works.

0 Likes
Message 5 of 6

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @drafting3QE6L 

 

You could give this example a try.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Imports System.IO
'Imports System.Windows.Forms
Sub main

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

	' Set options for folder browser dialog
	'set initial folder location
	Dialog.SelectedPath = "C:\Temp\"
	Dialog.ShowNewFolderButton = False
	Dialog.Description = "Choose the folder that contains the drawings..."

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

	Dim oList As New ArrayList

	Dim oDir As New DirectoryInfo(oFolder)

	iCount = 0
	For Each oFile As IO.FileInfo In oDir.GetFiles("*idw", IO.SearchOption.TopDirectoryOnly)
		oList.Add(oFile.FullName)
		iCount = iCount + 1
	Next

	oRUSure = MessageBox.Show(iCount & " drawings found... This could take a while, are you sure you want to run this batch?", _
	"iLogic", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

	If oRUSure = vbNo Then
		Return 'exit rule
	End If

	oPDF_Folder = oFolder & "PDF Folder\"

	'Check for the PDF folder and create it if it does not exist
	If Not System.IO.Directory.Exists(oPDF_Folder) Then
		System.IO.Directory.CreateDirectory(oPDF_Folder)
	End If

	For Each oItem In oList
		oDoc = ThisApplication.Documents.Open(oItem, True)

		Call Export_PDF(oDoc, oPDF_Folder)
		oDoc.Close()
	Next

	MessageBox.Show("PDF export is complete.", "iLogic", MessageBoxButtons.OK, MessageBoxIcon.Information)
	ThisDoc.Launch(oPDF_Folder)
End Sub


Sub Export_PDF(oDoc As Document, oPDF_Folder As String)


	oName = IO.Path.GetFileNameWithoutExtension(oDoc.Fullfilename)
	oPDF = oPDF_Folder & oName & ".pdf"


	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

	'set PDF Options
	oOptions.Value("All_Color_AS_Black") = 1
	oOptions.Value("Remove_Line_Weights") = 1
	oOptions.Value("Vector_Resolution") = 400
	oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange


	'Set the PDF target file name
	oDataMedium.FileName = oPDF

	Try
		'Publish document
		oPDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
	Catch
		Logger.Info("Error writing out PDF... " & oPDF)
	End Try



End Sub

 

 

EESignature

Message 6 of 6

drafting3QE6L
Contributor
Contributor

@Curtis_Waguespack It worked! Thank you for the help!

0 Likes