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/