Ilogic rule to save a PDF to desktop

Ilogic rule to save a PDF to desktop

Robin_Erich
Advocate Advocate
1,247 Views
2 Replies
Message 1 of 3

Ilogic rule to save a PDF to desktop

Robin_Erich
Advocate
Advocate

I want to make a rule that makes a PDF of a drawing and saves is to the desktop. 

Does this rule already exist, if not how should I go about this?

 

 

Did this reply help? Please click the „Accept Solution“ button. Helps me gather those Internet points
Check out my Ideas! I’m interested in your input and/or opinions.
https://autode.sk/3paEHwS
0 Likes
Accepted solutions (1)
1,248 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Here's one way to do it.

I left a lot of the PDF Translator's options in place but commented out so you can set them how you want them.

Here's the iLogic code.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This Rule '" & iLogicVb.RuleName & "' only works on Drawing Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document

Dim oPDFAddin As TranslatorAddIn
For Each oAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
	If oAddin.DisplayName = "Translator: PDF" Then
		oPDFAddin = oAddin
	End If
Next

'The following lines are to define needed aspects of the Translator, so we can modify its options.
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oContext As TranslationContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = oTO.CreateNameValueMap
Dim oDataMedium As DataMedium = oTO.CreateDataMedium

'The following If-Then statement defines the Options available, and their Values.
If oPDFAddin.HasSaveCopyAsOptions(oDDoc, oContext, oOptions) Then
	oOptions.Value("Publish_All_Sheets") = 1 ' 0 = False, 1 = True
	oOptions.Value("Launch_Viewer") = 1 ' 0 = False, 1 = True
	oOptions.Value("Publish_Mode") = 62721 'This seems to be the norm for exporting a normal drawing. There may be another value for 3D PDF's.
	'oOptions.Value("Enable_Measure") = 1
	'oOptions.Value("Enable_Markups") = 1
	'oOptions.Value("Output_Path") = 
	'oOptions.Value("Sheet_Metal_Flat_Pattern") = 0
	'oOptions.Value("Sheet_Metal_Part") = 1
	'oOptions.Value("Weldment_Symbol") = 0
	'oOptions.Value("BOM_Parts_Only") = 1
	'oOptions.Value("Instructions") = 0
	'oOptions.Value("iAssembly_3D_Models") = 0
	'oOptions.Value("iPart_3D_Models") = 0
	'oOptions.Value("Publish_Mass_Props") = 1
	'oOptions.Value("Publish_Screenshot") = 0
	'oOptions.Value("Facet_Quality") = 69379
	'oOptions.Value("Facet_Recompute_Tolerance") = 0.001
	'oOptions.Value("Sheet_Color") = 0
	'oOptions.Value("Custom_Begin_Sheet") = 1
	'oOptions.Value("Custom_End_Sheet") = 4   (it is not confirmed that this line works)
	oOptions.Value("All_Color_AS_Black") = 0 ' 0 = False, 1 = True
	oOptions.Value("Vector_Resolution") = 4800 ' DPI
	oOptions.Value("Remove_Line_Weights") = 0 ' 0 = False, 1 = True
	'oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	'oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintCurrentSheet
	'oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
	'oOptions.Value("Print_Excluded_Sheets") = 0 ' 0 = False, 1 = True (DOESN'T SEEM TO BE WORKING YET)
End If

'Set the PDF file name
'oDataMedium.FileName = ThisDoc.Path & "\" & ThisDoc.FileName(False) & ".pdf"
Dim oDeskTopDir As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory)
Dim oFileName = IO.Path.GetFileNameWithoutExtension(oDDoc.FullFileName)
oDataMedium.FileName = oDeskTopDir & "\" & oFileName & ".pdf"

'Check to see if the PDF already exists, if it does, ask if you want to over write existing or not.
If System.IO.File.Exists(oDataMedium.FileName) = True Then
	oAnswer = MsgBox("A PDF file with this name already exists." & vbCrLf &
	"Do you want to over write it with this new one?",vbYesNo + vbQuestion + vbDefaultButton2, "PDF ALREADY EXISTS")
	If oAnswer = vbNo Then Return
End If

'Publish PDF
oPDFAddin.SaveCopyAs(oDDoc, oContext, oOptions, oDataMedium)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS 💡and Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

Robin_Erich
Advocate
Advocate

Wonderful, thank you so much, I'll tinker with the PDF options.. this helps out a lot

Did this reply help? Please click the „Accept Solution“ button. Helps me gather those Internet points
Check out my Ideas! I’m interested in your input and/or opinions.
https://autode.sk/3paEHwS
0 Likes