Save copy as PDF options

Save copy as PDF options

wouter
Advocate Advocate
1,506 Views
4 Replies
Message 1 of 5

Save copy as PDF options

wouter
Advocate
Advocate

Hi,

I'm using some standard code to save copy certain sheets to a PDF.

But this only seems to work if I put the options on Sheet in range manually

 Options.png

Is it possible te check if the PDF options are set on Sheets in range or do so via ilogic?

Thank in advance!

 

SyntaxEditor Code Snippet

' Get the PDF translator Add-In.
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

' Get the sheet range
SheetRange = InputBox("Please enter the range of sheets you want to export as FIO" & vbLf & _
"You can use these input types:" & vbLf & "  ' 1 ' ,  ' 1-10 ' ", "Sheet range", "Enter sheet range")
If SheetRange = vbNullString Then Exit Sub
Dim SPL As Integer = InStr(SheetRange, "-")
Dim S1 As Integer
Dim S2 As Integer
If SPL > 0 Then
	S1 = Val(Left(SheetRange, SPL))
	S2 = Val(Mid(SheetRange, SPL + 1))
Else
	S1 = Val(SheetRange)
	S2 = Val(SheetRange)
End If

' Options for drawings...
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 4800
'oOptions.Value("Sheet_Range") = kPrintAllSheets
oOptions.Value("Custom_Begin_Sheet") = S1
oOptions.Value("Custom_End_Sheet") = S2

'Set the destination file name

modelFullFileName = ThisDrawing.ModelDocument.FullFileName
modelDirectoryName = IO.Path.GetDirectoryName(modelFullFileName)
modelFileName = IO.Path.GetFileNameWithoutExtension(modelFullFileName)

oDataMedium.FileName = modelDirectoryName & "\" & "FIO " & modelFileName & ".pdf"

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

 

0 Likes
Accepted solutions (1)
1,507 Views
4 Replies
Replies (4)
Message 2 of 5

Xun.Zhang
Alumni
Alumni

Hello @wouter,

Try below sample code and hope it helps!

Public Sub PublishPDF()
' Get the PDF translator Add-In.
Dim PDFAddIn As TranslatorAddIn
Set PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
'Set a reference to the active document (the document to be published).
Dim oDocument As Document
Set oDocument = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
' Check whether the translator has 'SaveCopyAs' options
If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
' Options for drawings...
oOptions.Value("All_Color_AS_Black") = 0
'oOptions.Value("Remove_Line_Weights") = 0
'oOptions.Value("Vector_Resolution") = 400
'oOptions.Value("Sheet_Range") = kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("Custom_End_Sheet") = 4
End If
'Set the destination file name
oDataMedium.FileName = "c:\\temp\\test.pdf"
'Publish document.
Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

Xun
0 Likes
Message 3 of 5

wouter
Advocate
Advocate

Hi,

 

Nope, doesn't work.

Only works if the pdf options in inventor save copy as are on sheets in range.

 

So I need some code that could set the pdf options to sheets in range.

or get a message box when running the code when it's not on sheets in range.

 

i was hoping if somebody here knows if thats possible.

0 Likes
Message 4 of 5

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@wouter,

 

Try below iLogic code to publish pdf of mentioned range. Sheet range should be always kPrintSheetRange (oOptions.Value("Sheet_Range") = PrintRangeEnum.kPrintSheetRange).

 

Sub Main()
	
	Dim SheetRange As String = InputBox("Please enter the range of sheets you want to export." & vbLf & _
	"You can use these input types:" & vbLf & "  ' 1 ' ,  ' 1-10 ' ", "Sheet range", "1-10")
	If SheetRange = vbNullString Then Exit Sub
	Dim SPL As Integer = InStr(SheetRange, "-")
	Dim L1 As Integer
	Dim L2 As Integer
	If SPL > 0 Then
		L1 = Val(Left(SheetRange, SPL))
		L2 = Val(Mid(SheetRange, SPL + 1))
	Else
		L1 = Val(SheetRange)
		L2 = Val(SheetRange)
	End If
	' Get the PDF translator Add-In.
	Dim PDFAddIn As TranslatorAddIn
	PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	'Set a reference to the active document (the document to be published).
	Dim oDocument As Document
	oDocument = ThisApplication.ActiveDocument
	Dim oContext As TranslationContext
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = kFileBrowseIOMechanism
	' Create a NameValueMap object
	Dim oOptions As NameValueMap
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	' Create a DataMedium object
	Dim oDataMedium As DataMedium
	oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
	' Check whether the translator has 'SaveCopyAs' options
	If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
	' Options for drawings...
	oOptions.Value("All_Color_AS_Black") = 0
	oOptions.Value("Remove_Line_Weights") = 0
	oOptions.Value("Vector_Resolution") = 400
	oOptions.Value("Sheet_Range") = PrintRangeEnum.kPrintSheetRange 
	oOptions.Value("Custom_Begin_Sheet") = L1
	oOptions.Value("Custom_End_Sheet") = L2
	End If
	'Set the destination file name
	oDataMedium.FileName = "C:\temp\test.pdf"
	'Publish document.
	Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 5 of 5

wouter
Advocate
Advocate

Ohhh I feel silly, i thougt filling in the custom begin and end sheet would automatically be sufficient. Guess not

Thank a lot anyway!

0 Likes