Export pdf to folder.

Export pdf to folder.

Jesper_S
Collaborator Collaborator
1,079 Views
3 Replies
Message 1 of 4

Export pdf to folder.

Jesper_S
Collaborator
Collaborator

Hi.

 

Im trying to get inventor to export my drawing to a folder on a network drive.

But my iLogic code doesnt work. 

I have found a code that i thought would work but i get an error saying

"The given path's format is not supported."

 

SyntaxEditor Code Snippet

'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-------

 

Whats wrong?

 

Using Inventor 2015

 

Jesper 


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Accepted solutions (1)
1,080 Views
3 Replies
Replies (3)
Message 2 of 4

Jesper_S
Collaborator
Collaborator
Never mind. Solved it.

//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Message 3 of 4

BrandonBG
Collaborator
Collaborator

Can you post the working code?

 

Brandon

0 Likes
Message 4 of 4

Jesper_S
Collaborator
Collaborator
Accepted solution

Because the network drive i was trying to export to was mapped to my computer i didnt need "\\" before may path in iLogic.

 

The code.

 

 

'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-------


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes