- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
A while ago i struggled with the below code and with your help i've worked with it pleasently. Now the question is to add the revision number of the exported document to the filename (if there is a revision number).
This code is used to export current or all open drawings to PDF and/or DWG. This saves a lot of time to export 50+ drawings of a project.
When i edit the code i'm coming to 2 outcome's:
1. it is looking at the revision number of the shown model and not the drawings revision number.
2. it is only looking at the current open drawing's revision number and adding it to all filenames.
Now i can update the revision numbers to the models by hand, but that's not ideal.
Sub Main() oInvApp = ThisApplication Dim myDate As String = Now().ToString("dd-MM-yyyy") myDate = myDate.Replace(":","") ' & " - " & TypeString userChoice = InputRadioBox("Defined the scope", "This Document", "All Open Documents", True, Title := "Defined the scope") UserSelectedActionList = New String(){"DWG & PDF", "PDF Only", "DWG Only"} UserSelectedAction = InputListBox("What action must be performed with selected views?", _ UserSelectedActionList, UserSelectedActionList(0), Title := "Action to Perform", ListName := "Options") Select UserSelectedAction Case "DWG & PDF": UserSelectedAction = 3 Case "PDF Only": UserSelectedAction = 1 Case "DWG Only": UserSelectedAction = 2 End Select If userChoice Then Call MakePDFFromDoc(oInvApp.ActiveDocument, myDate, UserSelectedAction) Else For Each oDoc In oInvApp.Documents If oDoc.DocumentType <> kDrawingDocumentObject Then Continue For Try If Len(oDoc.File.FullFileName) > 0 Then Call MakePDFFromDoc(oDoc, myDate, UserSelectedAction) End If Catch End Try Next End If End Sub Dim oInvApp As Inventor.Application Sub MakePDFFromDoc(ByRef oDocument As Document, DateString As String, UserSelectedAction As Integer) 'oPath = oDocument.Path 'oFileName = oDocument.FileName(False) 'without extension 'oDocument = ThisApplication.ActiveDocument Dim sDescript As String = oDocument.PropertySets("Design Tracking Properties")("Description").Value oPDFAddIn = oInvApp.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = oInvApp.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = oInvApp.TransientObjects.CreateNameValueMap oDataMedium = oInvApp.TransientObjects.CreateDataMedium oFullFileName = oDocument.File.FullFileName oPath = Left(oFullFileName, InStrRev(oFullFileName, "\")-1) oFileName = Right(oFullFileName, Len(oFullFileName)-InStrRev(oFullFileName, "\")) ' oFilePart = Left(oFileName, InStrRev(oFileName, ".") - 1) oFilePart = Left(oFileName, InStrRev(oFileName, ".") - 1) & " " & sDescript 'oRevNum = oDocument.iProperties.Value("Project", "Revision Number") 'oDocument = ThisApplication.ActiveDocument 'If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 0 oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'oOptions.Value("Custom_Begin_Sheet") = 2 'oOptions.Value("Custom_End_Sheet") = 4 ' End If 'get PDF target folder path 'oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF" oFolder = oPath & "\Export DWG & PDF (" & DateString & ")" oDirectoryName = System.IO.Path.GetDirectoryName(oFullFileName) 'Check for the PDF folder and create it if it does not exist If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & oFilePart & ".pdf" 'Publish document If (UserSelectedAction = 1) Or (UserSelectedAction = 3) Then oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)'For PDF's End If If (UserSelectedAction = 2) Or (UserSelectedAction = 3) Then oDocument.SaveAs(oFolder & "\" & oFilePart & ".dwg", True) 'For DWG's End If 'oDocument.SaveAs(oFolder & "\" & ThisDoc.ChangeExtension(".DWG"), True) 'For DWG's '------end of iLogic------- End Sub
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Hope this helps you!
Sub Main() oInvApp = ThisApplication Dim myDate As String = Now().ToString("dd-MM-yyyy") myDate = myDate.Replace(":","") ' & " - " & TypeString userChoice = InputRadioBox("Defined the scope", "This Document", "All Open Documents", True, Title := "Defined the scope") UserSelectedActionList = New String(){"DWG & PDF", "PDF Only", "DWG Only"} UserSelectedAction = InputListBox("What action must be performed with selected views?", _ UserSelectedActionList, UserSelectedActionList(0), Title := "Action to Perform", ListName := "Options") Select UserSelectedAction Case "DWG & PDF": UserSelectedAction = 3 Case "PDF Only": UserSelectedAction = 1 Case "DWG Only": UserSelectedAction = 2 End Select If userChoice Then Call MakePDFFromDoc(oInvApp.ActiveDocument, myDate, UserSelectedAction) Else For Each oDoc In oInvApp.Documents If oDoc.DocumentType <> kDrawingDocumentObject Then Continue For Try If Len(oDoc.File.FullFileName) > 0 Then Call MakePDFFromDoc(oDoc, myDate, UserSelectedAction) End If Catch End Try Next End If End Sub Dim oInvApp As Inventor.Application Sub MakePDFFromDoc(ByRef oDocument As DrawingDocument, DateString As String, UserSelectedAction As Integer) 'oPath = oDocument.Path 'oFileName = oDocument.FileName(False) 'without extension 'oDocument = ThisApplication.ActiveDocument Dim sDescript As String = oDocument.PropertySets("Design Tracking Properties")("Description").Value oPDFAddIn = oInvApp.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = oInvApp.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = oInvApp.TransientObjects.CreateNameValueMap oDataMedium = oInvApp.TransientObjects.CreateDataMedium oFullFileName = oDocument.File.FullFileName oPath = Left(oFullFileName, InStrRev(oFullFileName, "\")-1) oFileName = Right(oFullFileName, Len(oFullFileName)-InStrRev(oFullFileName, "\")) ' oFilePart = Left(oFileName, InStrRev(oFileName, ".") - 1) 'REF Model Dim oRefModel As Document = oDocument.ReferencedDocuments.Item(1) oRevNum = oRefModel.PropertySets("Inventor Summary Information").Item("Revision Number").Value Dim oExtra As String = Nothing If oRevNum = "" Or oRevNum Is Nothing Then oExtra = Nothing Else oExtra = "_" & oRevNum End If oFilePart = Left(oFileName, InStrRev(oFileName, ".") -1) & " " & sDescript & oExtra 'oRevNum = oDocument.iProperties.Value("Project", "Revision Number") 'oDocument = ThisApplication.ActiveDocument 'If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 0 oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'oOptions.Value("Custom_Begin_Sheet") = 2 'oOptions.Value("Custom_End_Sheet") = 4 ' End If 'get PDF target folder path 'oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF" oFolder = oPath & "\Export DWG & PDF (" & DateString & ")" oDirectoryName = System.IO.Path.GetDirectoryName(oFullFileName) 'Check for the PDF folder and create it if it does not exist If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & oFilePart & ".pdf" 'Publish document If (UserSelectedAction = 1) Or (UserSelectedAction = 3) Then oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)'For PDF's End If If (UserSelectedAction = 2) Or (UserSelectedAction = 3) Then oDocument.SaveAs(oFolder & "\" & oFilePart & ".dwg", True) 'For DWG's End If 'oDocument.SaveAs(oFolder & "\" & ThisDoc.ChangeExtension(".DWG"), True) 'For DWG's '------end of iLogic------- End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you for the quick reply. Since the time of the post i've been puzzling in the code and found a different solution:
Maybe it is a bit rough as i am not a coder, but it worked.
also added if there is no Rev number that it doesn't show.
Sub Main() oInvApp = ThisApplication Dim myDate As String = Now().ToString("dd-MM-yyyy") myDate = myDate.Replace(":","") ' & " - " & TypeString userChoice = InputRadioBox("Defined the scope", "This Document", "All Open Documents", True, Title := "Defined the scope") UserSelectedActionList = New String(){"DWG & PDF", "PDF Only", "DWG Only"} UserSelectedAction = InputListBox("What action must be performed with selected views?", _ UserSelectedActionList, UserSelectedActionList(0), Title := "Action to Perform", ListName := "Options") Select UserSelectedAction Case "DWG & PDF": UserSelectedAction = 3 Case "PDF Only": UserSelectedAction = 1 Case "DWG Only": UserSelectedAction = 2 End Select If userChoice Then Call MakePDFFromDoc(oInvApp.ActiveDocument, myDate, UserSelectedAction) Else For Each oDoc In oInvApp.Documents If oDoc.DocumentType <> kDrawingDocumentObject Then Continue For Try If Len(oDoc.File.FullFileName) > 0 Then Call MakePDFFromDoc(oDoc, myDate, UserSelectedAction) End If Catch End Try Next End If End Sub Dim oInvApp As Inventor.Application Sub MakePDFFromDoc(ByRef oDocument As Document, DateString As String, UserSelectedAction As Integer) 'oPath = oDocument.Path 'oFileName = oDocument.FileName(False) 'without extension 'oDocument = ThisApplication.ActiveDocument Dim sDescript As String = oDocument.PropertySets("Design Tracking Properties")("Description").Value Dim sRevnum As String = oDocument.PropertySets("Inventor Summary Information")("Revision Number").Value If oDocument.PropertySets("Inventor Summary Information")("Revision Number").Value = "" Then oREV = "" ElseIf oDocument.PropertySets("Inventor Summary Information")("Revision Number").Value IsNot "" Then oREV= " REV " End If oPDFAddIn = oInvApp.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = oInvApp.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = oInvApp.TransientObjects.CreateNameValueMap oDataMedium = oInvApp.TransientObjects.CreateDataMedium oFullFileName = oDocument.File.FullFileName oPath = Left(oFullFileName, InStrRev(oFullFileName, "\")-1) oFileName = Right(oFullFileName, Len(oFullFileName)-InStrRev(oFullFileName, "\")) ' oFilePart = Left(oFileName, InStrRev(oFileName, ".") - 1) oFilePart = Left(oFileName, InStrRev(oFileName, ".") - 1) & " " & sDescript & oREV & sRevNum 'oRevNum = oDocument.iProperties.Value("Project", "Revision Number") 'oDocument = ThisApplication.ActiveDocument 'If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 0 oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'oOptions.Value("Custom_Begin_Sheet") = 2 'oOptions.Value("Custom_End_Sheet") = 4 ' End If 'get PDF target folder path 'oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF" oFolder = oPath & "\Export DWG & PDF (" & DateString & ")" oDirectoryName = System.IO.Path.GetDirectoryName(oFullFileName) 'Check for the PDF folder and create it if it does not exist If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & oFilePart & ".pdf" 'Publish document If (UserSelectedAction = 1) Or (UserSelectedAction = 3) Then oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)'For PDF's End If If (UserSelectedAction = 2) Or (UserSelectedAction = 3) Then oDocument.SaveAs(oFolder & "\" & oFilePart & ".dwg", True) 'For DWG's End If 'oDocument.SaveAs(oFolder & "\" & ThisDoc.ChangeExtension(".DWG"), True) 'For DWG's '------end of iLogic------- End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Well done!
Yeah, that works too.
You will face one problem if no revision exists. As you will add the Text " REV " or space " " to the file name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If oDocument.PropertySets("Inventor Summary Information")("Revision Number").Value = "" Then oREV = "" ElseIf oDocument.PropertySets("Inventor Summary Information")("Revision Number").Value IsNot "" Then oREV= "REV " End If
To my logic i prefent this from happening with this If section.
If there is "nothing" filled in to the revision number value, "nothing" will be added.
If something is filled into te revision number value, REV will be added in front of the Revision number value.
That is wat the goal is with this section. That REV is not always shown, only when there is a Revision.
So far it is working as intended. Tried it with multiple documents so far so good.