Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PDF Export all open drawings wont iterate

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
truscher
824 Views, 2 Replies

PDF Export all open drawings wont iterate

Hi folks!

I'm tying to create a rule this checks all the open files, and exports a PDF of any .dwg or .idw files that are open. I fould some code on the boards and cobbled something together, but it does not work as expected. I have included the code below and as an attachment for easy use. what should happen is call the file manager and and collect all open docs, for each loop trjough each, and if it is a drawing file, export PDF. What actually happens is it exports he doc that the rule was lauched from as many times as there are open drawing docs. Please tkae a look at the code and provide some guidence! this is a big deal for us! Without further dissembling, here is the code:

fmgr = ThisApplication.Filemanager
For Each file In fmgr.files
doc = ThisApplication.Documents.ItemByName (file.fullfileName)
' path = ThisApplication.Documents.ItemByName (file.path)
If (doc.documenttype = kDrawingDocumentObject) Then 'Found an dwg

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("Project", "Revision Number")
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

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 = oPath & "\PDF"
MessageBox.Show(oFolder, "Path")


'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 & "\" & oFileName & _
" Rev" & oRevNum & ".pdf"

On Error Goto handlePDFLock

'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

' MessageBox.Show("crap", "Name")
End If
Next file

'--------------------------------------------------------------------------------------------------------------------

Exit Sub

handlePDFLock:
MessageBox.Show("PDF could not be saved, most likely someone else has it open", "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
Resume Next

'Show message box
MessageBox.Show("Drawing saved and PDF Exported to LAST EDITED document folder/PDF", "Save I-logic")

2 REPLIES 2
Message 2 of 3

Hi truscher,

 

Here is a modification of the rule that I think will do what you're after (attached is the same rule in a *.txt file in case it helps).

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim oDoc As Inventor.Document
For Each oDoc In ThisApplication.Documents.VisibleDocuments
     If (oDoc.documenttype = kDrawingDocumentObject) Then 'Found a drawing
     'find the postion of the last backslash in the path
    oFNamePos = InStrRev(oDoc.fullfileName, "\", -1)   
    'get the file name with the file extension
    oName = Right(oDoc.fullfileName, Len(oDoc.fullfileName) - oFNamePos)
    'get the path of the folder containing the file
    oPath = Left(oDoc.fullfileName, Len(oDoc.fullfileName) - Len(oName))
     'get the file name (without extension)
    oShortName = Left(oName, Len(oName) - 4)
    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
    
    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 = oPath & "\PDF"
    
    '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 & "\" & oShortName & ".pdf"
    
    On Error Goto handlePDFLock
    
    'Publish document
    oPDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
      End If
Next oDoc

'Show message box
MessageBox.Show("PDF(s) exported to: " & oFolder , "iLogic")
'--------------------------------------------------------------------------------

Exit Sub

handlePDFLock:
MessageBox.Show("At least one PDF could not be saved, " _
& "most likely someone else has it open.", _
"No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
Resume Next

 

Message 3 of 3

Thanks, That did it. Would it be possible to modify iProperties on these files as well?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report