How To Identify Processes Ready for iLogic Automation in Autodesk Inventor

fy25-inventor-campaign-02.jpg

Are you tired of doing the same task over and over? Had enough of clicking the same options day in and day out? Frustrated by the fact you forgot to click one option and have to start over? In this blog post, I'll show you how to identify processes ripe for iLogic Automation in Autodesk Inventor.

 

Using Inventor is a simple undertaking, getting Inventor to do what you want is challenging especially when you ask yourself the question 'Why isn't this a command?' take for instance the creation of a PDF. There are a few options out of the box: 'Export', 'Print', and 'Save Copy As'. That's all well and good, but what if the situation called for placing something in the same location but with a specific name? What about attaching them to an email or sending them to SharePoint? Send them to a specific printer? Put them in a junk folder so you can review them?

 

You might think these things will only take a few seconds to complete, but do they? Any time a file is handled there is room for error. No matter how robust a process is, there is always room for error.  My old high school drafting teacher drilled into my head that if something saves you a few seconds per action, that can add up to an hour per week, or 52 hours a year. Think about how much you can get done in a week and a half...

 

Let's start with the easy part and set up some iLogic code to print a PDF:

 

'Variables
oAddIns = ThisApplication.ApplicationAddIns
oTG = ThisApplication.TransientObjects

Dim FileSysObj = CreateObject("Scripting.FileSystemObject")

'Get user name
objNetwork = CreateObject("Wscript.Network")
UserName = objNetwork.UserName

PDFPath = "C:\_PDF_Junk\"

'If File exist Then Return True, Else Return False create folder
If FileSysObj.folderExists(PDFPath) = True Then
	'MsgBox("File Exists")
Else
	'MsgBox("File does NOT exist")
	FileSysObj.createfolder(PDFPath)
End If

'add pdf drawings
Dim oDoc As Document
oDoc = ThisDoc.Document
oDocName = System.IO.Path.GetDirectoryName(oDoc.FullFileName) & "\" & System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)

Dim PDFAddIn As TranslatorAddIn
Dim oContext As TranslationContext
Dim oOptions As NameValueMap
Dim oDataMedium As DataMedium

PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets


oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

'Get user name
objNetwork = CreateObject("Wscript.Network")
UserName = objNetwork.UserName

PDFFileName = Replace(oDoc.DisplayName, ".idw", "")
PDFFileName = PDFFileName & "_Rev_"& iProperties.Value("Project", "Revision Number") & ".pdf"
oDataMedium.FileName = PDFPath & PDFFileName

Call PDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)

Dim oShell As Object= CreateObject("Shell.Application")
Dim Wnd As Object

For Each Wnd In oShell.Windows
	Select Case Wnd.Name
		Case "File Explorer"
			If Wnd.Document.folder.self.Path = PDFPath Then
				AppActivate(Wnd.Document.folder.self.name)
				Exit Sub
			End If
	End Select
Next

Shell("explorer" & " " & PDFPath, vbNormalFocus)

 This code allows us to create a PDF file with certain company standards selected, and place it in a folder on the user's C: drive. I've named the folder "_PDF_Junk" so that any PDF placed here is a local copy specific to the user, allowing them to easily share the PDF and quickly locate any PDF by 'Pinning' the location on their Explorer window.

 

 

This also checks to see if the folder exists so the PDF has a destination. If not, it creates the folder. The final benefit of this is that at the end, a Windows Explorer window will be opened to the designated address, allowing for the ability to quickly find the created PDF.

This code is easily modified by changing the output directory. 
Example: PDFPath = "C:\_PDF_Junk\" change to "Z:\ExampleFolder\"

In this case a Z: drive would need to be mapped on the user's PC. Changing this variable allows for the Windows Explorer to open to that directory.

 

Notice that you can easily rename the file, in this example, I add the revision level to the filename. Using the current drawing document name, remove the extension of ".idw" and then add the revision level as a string that is populated from the iProperty of the file. Finally, add ".pdf" to ensure the correct file type.

 

Example: 

PDFFileName = Replace(oDoc.DisplayName, ".idw", "")

PDFFileName = PDFFileName & "_Rev_"& iProperties.Value("Project", "Revision Number") & ".pdf"

 

7 Comments
indiamachinemart_in
Community Visitor

Nice one I was looing for this

 

AndrewHumiston
Advocate
I'm glad to help. Please let me know if you have any questions or concerns.
Also, please let me know if you have any ideas you'd like to see ilogic code for. I have quite a few items to share if you'd like to see more like this.
Thank you!
haleproduction0
Community Visitor

Thank you so much I have been looking for this for so long. 

AndrewHumiston
Advocate
Glad to help. Please let me know if you have any questions or ideas on doing something more.
AndrewHumiston
Advocate
Thank you! Let me know if you have any ideas or things you'd like to see.
AndrewHumiston
Advocate

you are welcome. please let me know if there is anything else you'd like to see.

jroyse
Participant

Thank you, I would definitely like to see more stuff like this @AndrewHumiston