ilogic to export pdf to folder,

ilogic to export pdf to folder,

Anonymous
Not applicable
1,819 Views
4 Replies
Message 1 of 5

ilogic to export pdf to folder,

Anonymous
Not applicable

We have a few users, we all export PDFs to one folder (for purchasing) on our network.

I have found some samples here in the forum, but they do way more then I need.

Any direction would be helpful.

 

Outline:

Export PDF to folder , (F:\VENDOR), save as a current drawing name, over right existing file.

 

sample that is close??

 

'query user
question = MessageBox.Show("Is a .PDF Export To Monitor Required?", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
'set condition based on answer
If question = vbYes Then
'------start of iLogic-------
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") = 1
oOptions.Value("Custom_End_Sheet") = 10
End If

'get PDF target folder path
oFolder = Left(oPath, InStrRev(oPath, "G:\Dokumentation\Ritningar\Ritningar Monitor\$Ritningar From CAD")) &"G:\Dokumentation\Ritningar\Ritningar Monitor\$Ritningar From CAD"
'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

If iProperties.Value("Project", "Revision Number") >= "1" Then
'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
"-" & oRevNum & ".pdf"
Else
'Set the destination file name
oDataMedium.FileName = oFolder & "\" & oFileName & ".pdf"
End If
Else
Return
End If

On Error Goto handlePDFLock

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

'--------------------------------------------------​--------------------------------------------------​----------------

Exit Sub

handlePDFLock:MessageBox.Show("PDF not created, 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")
'------end of iLogic-------

 

0 Likes
1,820 Views
4 Replies
Replies (4)
Message 2 of 5

Ktomberlin
Advocate
Advocate
Just Change this section shown below:
'get PDF target folder path
oFolder = "F:\VENDOR"
'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

0 Likes
Message 3 of 5

frederik_vollbrecht
Advocate
Advocate
 '------start of iLogic-------
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") = 1
	oOptions.Value("Remove_Line_Weights") = 1
	oOptions.Value("Vector_Resolution") = 600
	oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	'oOptions.Value("Custom_Begin_Sheet") = 2
	'oOptions.Value("Custom_End_Sheet") = 4
End If

If oFileName ="" Then
	i = MessageBox.Show("Die Datei muss erst gespeichert werden!", "Fehler in Speichervorgang", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
	Return
End If

'Foldername and Path
oFolder= "F:\VENDOR"

'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

'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'------end of iLogic-------

Here you are. No Error Handling. I have written some code to export all drawings for alle parts, even in sub-assemblys.
If you are interested I'll post a sample here.

0 Likes
Message 4 of 5

Anonymous
Not applicable

frederik,  thank you,

 

Yes, Can you post, your other code?

 

thanks

0 Likes
Message 5 of 5

frederik_vollbrecht
Advocate
Advocate

Hi,

 

here is it. The Drawings have to be in the same folder as the Part/Assembly. As the code is optimized for my workflow some adaptation could be required.

 

Spoiler
'based on script from curtis Waguespack
'customization by Frederik Vollbrecht

'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


'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)

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

oFolder = "D:\VENDOR" '&  iProperties.Value("Project", "Stock Number")

'Check for the 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 PDF 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
idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
'check to see that the model has a drawing of the same path and name
If(System.IO.File.Exists(idwPathName)) Then
        Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.Documents.Open(idwPathName, 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 PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
    oDrawDoc.Close
    
Else
'If the model has no drawing of the same path and name - do nothing
End If
Next
'- - - - - - - - - - - - -


'- - - - - - - - - - - - -Top Level PDF Drawing - - - - - - - - - - - -
oAsmDrawing = ThisDoc.ChangeExtension(".idw")
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 PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)
   
'show msg Box that files have exported and open export folder. Comment out if not necessary
MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'open the folder where the new files are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)

If the solution was helpful, mark accepted or kudo 😉