export all open files to pdf with revision level

export all open files to pdf with revision level

eric_smythC4KJK
Participant Participant
240 Views
3 Replies
Message 1 of 4

export all open files to pdf with revision level

eric_smythC4KJK
Participant
Participant

I am still somewhat new to iLogic, I have this code that I have gotten from the forums and modified to export all open drawings to pdf in a single folder. It works great with only one problem. I include a custom iproperty of "REV LEVEL" in the file name. The issue is it takes the revision level of the first drawing and uses it for all the other drawings. How is that value reset or changed between each loop thru the code? 

 

Sub Main()
  Dim myDate As String = Now().ToString("yyyy-MM-dd HHmmss")
  myDate = myDate.Replace(":","")  ' & " - " & TypeString
 userChoice = InputRadioBox("Defined the scope", "This Document", "All Open Documents", True, Title := "Defined the scope")
 UserSelectedActionList = New String(){"DXF & PDF", "PDF Only", "DXF Only"}
  UserSelectedAction = InputListBox("What action must be performed with selected views?", _
          UserSelectedActionList, UserSelectedActionList(0), Title := "Action to Perform", ListName := "Options")
      Select UserSelectedAction
   Case "DXF & PDF": UserSelectedAction = 3
   Case "PDF Only": UserSelectedAction = 1
   Case "DXF Only":    UserSelectedAction = 2
   End Select
 If userChoice Then
   Call MakePDFFromDoc(ThisApplication.ActiveDocument, myDate, UserSelectedAction)
  Else
   For Each oDoc In ThisApplication.Documents
    If oDoc.DocumentType = kDrawingDocumentObject
     Try
      If Len(oDoc.File.FullFileName)>0 Then
       Call MakePDFFromDoc(oDoc, myDate, UserSelectedAction)
      End If
     Catch
     End Try
    End If
   Next
  End If
 End Sub
 Sub MakePDFFromDoc(ByRef oDocument As Document, DateString As String, UserSelectedAction As Integer)
 ' oPath = oDocument.Path
 ' oFileName = oDocument.FileName(False) 'without extension
  'oDocument = ThisApplication.ActiveDocument
  oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
  ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
  oContext = ThisApplication.TransientObjects.CreateTranslationContext
  oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
  oOptions = ThisApplication.TransientObjects.CreateNameValueMap
  oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
 oFullFileName = oDocument.File.FullFileName
 oPath = "C:\Users\eric.smyth\OneDrive - CPM Holdings Inc\Desktop\pdf folder"
  'oPath = Left(oFullFileName, InStrRev(oFullFileName, "\")-1)
  oFileName = Right(oFullFileName, Len(oFullFileName)-InStrRev(oFullFileName, "\"))
  oFilePart = Left(oFileName, InStrRev(oFileName, ".")-1)
 'oRevNum = oDocument.iProperties.Value("Project", "Revision Number")
 oRevNum1= iProperties.Value("Custom", "REV LEVEL")
  'oDocument = ThisApplication.ActiveDocument
 ' If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
  oOptions.Value("All_Color_AS_Black") = 0
  oOptions.Value("Remove_Line_Weights") = 0
  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
  'oFolder = oPath & "\iLogic PDF's (" & DateString & ")"
 '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
 'DataMedium.FileName = "\" & oFileName & "_r" & oRevNum1 & ".pdf"
  oDataMedium.FileName = oFolder & "\" & oFilePart & "_r" & oRevNum1 & ".pdf"
  'PDFName = PDFPath & "\" & oFileName & "_r" & oRevNum1 & ".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 & ".dxf", True) 'For DXF's
  End If
  'oDocument.SaveAs(oFolder & "\" & ThisDoc.ChangeExtension(".dxf"), True) 'For DXF's
  '------end of iLogic-------
 End Sub

 

0 Likes
241 Views
3 Replies
Replies (3)
Message 2 of 4

Ethibaudeau
Advocate
Advocate

Your sub "MakePDFFromDoc()" is being called with "ThisApplication.ActiveDocument". Therefore, it is always only going to make the PDF from the active document on screen.

 

You instead need to loop through each of the open document(s), calling "MakePDFFromDoc" on each document.

0 Likes
Message 3 of 4

eric_smythC4KJK
Participant
Participant

isn't Sub Main() looping thru all "ThisApplication.Documents" and then calling "MakePDFFromDoc" on each document? It is saving all the drawings as pdfs, its not getting the correct "rev level" for each.

0 Likes
Message 4 of 4

Ethibaudeau
Advocate
Advocate

Ah, sorry about that, you are correct. I misread the code.

 

I generally avoid iLogic, and go straight to the Inventor API. My guess is the iLogic: "iProperties" is grabbing info for the active document.

 

I see you might have been trying 'Document.iProperties" in the commented code, which would have errored because that doesn't exist. Instead, try the Inventor API: "Document.PropertySets"

 

https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=Document_FilePropertySets

 

Example here:
https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=iPropertyGetValue_Sample