Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I created two external rules to export all open drawings to PDF, the first rule is only to run a main rule, where the export is made, but I'm having an issue. The only drawing exported is the one where I run the first rule, saved as different names.
For Each doc As Document In ThisApplication.Documents.VisibleDocuments
If doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
iLogicVb.Automation.RunExternalRule(doc, "SavePDF")
End If
Next
MessageBox.Show("All PDFs created", "Ready!", MessageBoxButtons.OK)
Sub Main()
FileName = ThisDoc.FileName(True) 'with extension
FileExtension = Right(FileName, 3)
If FileExtension = "idw" Then
Save_As_PDF
Else If FileExtension = "dwg" Then
Save_As_PDF
Else
ErrorMessage
End If
End Sub
Sub Save_As_PDF
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False)
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
oRevNum = iProperties.Value("Project", "Revision Number")
WorkspacePath = ThisDoc.WorkspacePath() 'Gets the workspace path
WorkspacePathLength = Len(WorkspacePath) 'Gets the length of the workspace path string
PathOnly = ThisDoc.Path 'Gets just the path of the file
DirectoryPath = Strings.Right(PathOnly, PathOnly.Length - WorkspacePathLength) 'Removes the workspace path from fullpath
PDFPath = ThisDoc.Path & "\2D_PDF" 'Sets the directory that the pdf should be saved in
PDFName = PDFPath & "\" & ThisDoc.FileName(False) & "_" & oRevNum & ".pdf" 'Saves the pdf in the desired location
oDataMedium.FileName = PDFName
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
If Not System.IO.Directory.Exists(PDFPath) Then 'checks to see if that directory exists, if not, it is created
System.IO.Directory.CreateDirectory(PDFPath)
End If
'Check to see if the PDF already exists, if it does, ask if you want to overwrite it or not.
If System.IO.File.Exists(PDFName) = True Then
oAnswer = MsgBox("A PDF file with this name already exists." & vbCrLf &
"Do you want to overwrite it with this new one?",vbYesNo + vbQuestion + vbDefaultButton2, "PDF ALREADY EXISTS")
If oAnswer = vbNo Then Exit Sub
End If
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'MessageBox.Show("PDF created","Message", MessageBoxButtons.OK)
End Sub
Sub ErrorMessage
i = MessageBox.Show("This Is Not a drawing File. No PDF will be created.", "Create PDF", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
End Sub
All files were create, but they're all the same.
I think there's some error in my code, but I couldn't figure out. Can anyone help me?
Thanks a lot.
Solved! Go to Solution.