Automatic PDF Macro

Automatic PDF Macro

Anonymous
Not applicable
3,677 Views
6 Replies
Message 1 of 7

Automatic PDF Macro

Anonymous
Not applicable

Hello,

 

I'm not that good with programming so can someone help me? I need a macro that everytime I save a IDW file (to a folder or just edited and saved) the macro triggers and creates a PDF file of this IDW file and saves it to the same place or a diferent folder. It might sound simple but I'm really struggling with it. Help!

 

Thanks

Accepted solutions (1)
3,678 Views
6 Replies
Replies (6)
Message 2 of 7

MechMachineMan
Advisor
Advisor

Hi,

 

Take a peak at some of the links in my signature or browse around the forums some more.

 

You just need iLogic code to export the PDF, and then to add it on event trigger. If you have 2018.2.3 (the latest version), there are global event triggers which make this very easy.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 7

JamieVJohnson2
Collaborator
Collaborator
Accepted solution
 If invdoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
                            Dim drawDoc As Inventor.DrawingDocument = invdoc
                            ReadInventorData(batchFile)
                            'warn user if errors (show error list, in log and on screen), choose to continue to plot or skip file and quit this routine
                            Dim errorMng As ErrorManager = invApp.ErrorManager
                            If errorMng.HasErrors = True Then
                                Dim errors As String = errorMng.AllMessages
                                MsgBox("This drawing has errors: " & drawDoc.FullFileName & vbCr & errors, MsgBoxStyle.SystemModal)
                                batchFile.Errors += " Document errors:" & errors
                                booHasErrors = True
                            End If
                            If booHasErrors = True Then
                                If MsgBox("Document has errors continue to PDF?", MsgBoxStyle.YesNo + MsgBoxStyle.SystemModal) = MsgBoxResult.No Then
                                    batchFile.Errors += " Document not exported to PDF"
                                End If
                            End If
                            'export file to PDF using 'all sheets', 'default sizes', 'file name - Rev name' (keep color)
                            Dim PDFAddin As TranslatorAddIn
                            PDFAddin = invApp.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
                            Dim tContext As TranslationContext
                            tContext = invApp.TransientObjects.CreateTranslationContext
                            tContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
                            Dim nvmOptions As NameValueMap
                            nvmOptions = invApp.TransientObjects.CreateNameValueMap
                            Dim dm As DataMedium
                            dm = invApp.TransientObjects.CreateDataMedium
                            'create PDFprint filename
                            Dim rev As String = drawDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value
                            batchFile.Revision = rev
                            batchFile.PDF = VaultedFiles.Instance.Add(New SIO.FileInfo(CreatePDFFilePath(batchFile.Drawing.WorkFile.FullName, batchFile.Revision)))
                            'project path
                            Dim dirName As String = System.IO.Path.GetDirectoryName(batchFile.PDF.WorkFile.FullName)
                            System.IO.Directory.CreateDirectory(dirName)
                            If PDFAddin.HasSaveCopyAsOptions(drawDoc, tContext, nvmOptions) Then
                                With nvmOptions
                                    .Value("All_Color_AS_Black") = 0
                                    .Value("Remove_Line_Weights") = 0
                                    .Value("Vector_Resolution") = 400
                                    .Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
                                End With
                                dm.FileName = batchFile.PDF.WorkFile.FullName
                                'replace old files:
                                Try
                                    If batchFile.PDF.WorkFile.Exists Then
                                        ClearFileAttributes(batchFile.PDF.WorkFile)
                                        batchFile.PDF.WorkFile.Delete()
                                    End If
                                    PDFAddin.SaveCopyAs(drawDoc, tContext, nvmOptions, dm)
                                    ' batchFile.PDFFile = batchFile.PDFFile 'this will force a check to see if the file exists, without us doing so
                                Catch ex As Exception
                                    MsgBox("Error removing or writing file; perhaps existing file can't be overwritten.  Skipping file." & vbCr & batchFile.PDF.WorkFile.FullName, MsgBoxStyle.SystemModal)
                                    batchFile.Errors += " File not printed to PDF."
                                End Try
                            End If
                            If batchFile.Drawing.FileOpened Then batchFile.Drawing.CloseFile()
                        End If

Here are the guts I use to print to PDF (and some of my other error checking stuff).  written in vb.net, but should work fine in today's iLogic.

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
Message 4 of 7

Anonymous
Not applicable

It prints to PDF when you press "save button" or you press it everytime you want to print?

 

Regards

0 Likes
Message 5 of 7

MechMachineMan
Advisor
Advisor

If you set it up on the event trigger, it will run the code (which will export it) every time that save event is encountered.

 

If you don't set it up on the event trigger, you would have to run the rule from the iLogic browser.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 6 of 7

pl.sivakumar
Advocate
Advocate
can Possible get VB.net code for the same
0 Likes
Message 7 of 7

pl.sivakumar
Advocate
Advocate
This pdf output is editable in Adobe Pro. Can possible to convert images & re-convert them to pdf output?
0 Likes