Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Export drawing to pdf - how to change/trim destination folder path

Pav3L
Advocate

Export drawing to pdf - how to change/trim destination folder path

Pav3L
Advocate
Advocate

Hi,

I have a rule not created by me, which you can see at the bottom of this post, that exports my drawing to PDF, but the PDF is created in the drawing file folder, I would like to change the target folder to our server, but I have no idea how.

 

The file path and name generated by the code:

 

 

oDataMedium.FileName = ThisDoc.PathAndFileName(False) & ".pdf"

 

 

is as follows: "c:\_Vault_Pracovni\externi\_ORDERS - ZAKÁZKY\2023 (zak. 51163 - )\51215\Test.pdf"

 

How to modify the file path to save the file Test.pdf in the following folder?

"\\192.168.1.200\data\cad\externi\_ORDERS - ZAKÁZKY\2023 (zak. 51163 - )\51215\"

 

As you can see the end part "\externi\_ORDERS - ZAKÁZKY\2023 (zak. 51163 - )\51215\" of the file path is the same, because our server mimics the path of the drawing file except the starting part "c:\_Vault_Pracovni" which I need to change to "\\192.168.1.200\data\cad".

 

Please note this "\\192.168.1.200\data\cad\externi\_ORDERS - ZAKÁZKY\2023 (zak. 51163 - )\51215\" is not a fixed folder, each order has its own number and specific year that changes so I think that ThisDoc.FileName(False) & ".pdf" should be used but then how to modify the starting part of the path?

 

 

 

'Get the PDF translator Add-In.
Dim PDFAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

'a reference to the active document (the document to be published).
Dim oDocument As Document = ThisApplication.ActiveDocument

Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

'Create a NameValueMap object
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap

'Create a DataMedium object
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium

oOptions.Value("Sheet_Range") = PrintRangeEnum.kPrintAllSheets

'Check whether the translator has 'SaveCopyAs' options
If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
	' Options for drawings...
	oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	oOptions.Value("All_Color_AS_Black") = 0
	'oOptions.Value("Sheet_Range") = PrintRangeEnum.kPrintAllSheets
	oOptions.Value("Remove_Line_Weights") = 1
	'oOptions.Value("Vector_Resolution") = 400
	'oOptions.Value("Custom_Begin_Sheet") = 2
	'oOptions.Value("Custom_End_Sheet") = 4
End If

'the destination file name
oDataMedium.FileName = ThisDoc.PathAndFileName(False) & ".pdf"

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

 

 

 

0 Likes
Reply
Accepted solutions (1)
294 Views
1 Reply
Reply (1)

Pav3L
Advocate
Advocate
Accepted solution

I figured it out with the help of Mr. Google.

Old line: 

oDataMedium.FileName = ThisDoc.PathAndFileName(False) & ".pdf"

 Replacement:

oDataMedium.FileName = "\\192.168.1.200\data\cad\" & Mid(ThisDoc.PathAndFileName(False),20) & ".pdf"

 

The whole rule, I also added a folder check.

'Get the PDF translator Add-In.
Dim PDFAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

'Reference to the active document (the document to be published).
Dim oDocument As Document = ThisApplication.ActiveDocument

Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

'Create a NameValueMap object
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap

'Create a DataMedium object
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium

oOptions.Value("Sheet_Range") = PrintRangeEnum.kPrintAllSheets

'Check whether the translator has 'SaveCopyAs' options
If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
	'Options for drawings...
	oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	oOptions.Value("All_Color_AS_Black") = 0
	oOptions.Value("Remove_Line_Weights") = 1
	oOptions.Value("Vector_Resolution") = 400
	'oOptions.Value("Sheet_Range") = PrintRangeEnum.kPrintAllSheets
	'oOptions.Value("Custom_Begin_Sheet") = 2
	'oOptions.Value("Custom_End_Sheet") = 4
End If

'The destination folder and file name
oFolder = "\\192.168.1.200\data\cad\" & Mid(ThisDoc.Path, 20)
oDataMedium.FileName = "\\192.168.1.200\data\cad\" & Mid(ThisDoc.PathAndFileName(False), 20) & ".pdf"

'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

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

 a 

0 Likes