Batch PDF Export from assembly not working

Batch PDF Export from assembly not working

JoshuaNAM
Advocate Advocate
2,854 Views
21 Replies
Message 1 of 22

Batch PDF Export from assembly not working

JoshuaNAM
Advocate
Advocate

Hi Inventor users,

 

I've copied several ilogic codes from different forums and edited them a bit to increase our productivity.when exporting to different file formats.

 

When using the rule to batch export a pdf from an inventor dwg we get the following error message:

 

Failed to publish DWF file

 

When running the rule from a standalone laptop (where the code was created) the illogic rule works correctly. When running the rule on a workstation and the rules saved on a sever the export fails.

 

We’ve reset the autodesk userprofile but that didn’t help.

We’ve reinstalled DWG trueview and Design Review but that didn’t make a diffenrence either.

 

Enclosed you’ll find the illogic code that we’re talking about.

 

Can anyone help me out? 

 

 

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)
oRevNum = iProperties.Value("Project", "Revision Number")

'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If

'get user input
RUsure = MessageBox.Show ( _
"This will create a PDF file for all of the assembly components that have drawing (dwg) files." _
& vbLf & "This rule expects that the drawing file shares the same name and location as the component." _
& vbLf & " " _
& vbLf & "Are you sure you want to create PDF Drawings for all of the assembly components?" _
& vbLf & " " _
& vbLf & "This could take a while.", "iLogic  - Batch Output PDFs ",MessageBoxButtons.YesNo)

If RUsure = vbNo Then
Return
Else
End If

'- - - - - - - - - - - - -PDF setup - - - - - - - - - - - -
oPath = ThisDoc.Path
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

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") = 1
oOptions.Value("Custom_End_Sheet") = 1

'get PDF target folder path
oFolder = oPath & "\" & oAsmName & "-Rev_" & oRevNum & "-PF" & "\" & oAsmName & "-Rev_" & oRevNum & "-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
'- - - - - - - - - - - - -

'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document

'work the the drawing files for the referenced models'this expects that the model has a drawing of the same path and name
For Each oRefDoc In oRefDocs
dwgPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "dwg"
'check to see that the model has a drawing of the same path and name
If(System.IO.File.Exists(dwgPathName)) Then
                        Dim oDrawDoc As DrawingDocument
                oDrawDoc = ThisApplication.Documents.Open(dwgPathName, True)
            oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3)

            On Error Resume Next ' if PDF exists and is open or read only, resume next
                 'Set the PDF target file name
                oDataMedium.FileName = oFolder & "\" & oFileName & "pdf"
                'Write out the PDF
                Call oPDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
            'close the file
                oDrawDoc.Close
Else
'If the model has no drawing of the same path and name - do nothing
End If
Next
'- - - - - - - - - - - - -

'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
oAsmDrawing = ThisDoc.ChangeExtension(".dwg")
oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmDrawing, True)
oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -3)
'write out the PDF for the Top Level Assembly Drawing file
On Error Resume Next ' if PDF exists and is open or read only, resume next
 'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & "pdf"
'Write out the PDF
Call oPDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)
'Close the top level drawing
oAsmDrawingDoc.Close
'- - - - - - - - - - - - -

MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'open the folder where the new ffiles are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)

 

0 Likes
Accepted solutions (1)
2,855 Views
21 Replies
Replies (21)
Message 21 of 22

bradeneuropeArthur
Mentor
Mentor
Much appreciated...

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 22 of 22

pl.sivakumar
Advocate
Advocate

Can I get VBA code for the same function

0 Likes