Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic Export to PDF options

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Formsprag
7907 Views, 3 Replies

iLogic Export to PDF options

First let me say that I am a complete novice when it comes to iLogic coding or coding in general. I have been extremely lucky to be able to find code snippets on the web that I have been able to edit to suite my needs. However; I have a piece of code that I don’t understand how to modify and I was hoping someone could lead me in the right direction.

 

I would like to be able to define the following export to PDF options defined by Curtis Waguespack in the code by Luke Davenport on Cadline Community:

 

PDF Options:

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 3731 StartFragment: 314 EndFragment: 3699 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
oOptions.Value("Sheet_Range") =
Inventor.PrintRangeEnum.kPrintAllSheets

Export Code:

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 15604 StartFragment: 314 EndFragment: 15572 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

' This is an example iLogic rule by Luke Davenport on Cadline Community' It creates a 'folder browser dialog' to allow user to pick a directory location' This selected directory location is then used for a generic PDF export operation' Please modify to suit your requirements....

Imports System.Windows.Forms
    
' Get current location of this file
Dim ExportPath As String = ThisDoc.Path

' Check that this file has been saved and actually exists on disk
If String.IsNullOrEmpty(ExportPath) Then
    MsgBox("This file has not yet been saved and doesn't exist on disk! - please save it first",64, "Formsprag iLogic")
Return
End If

' Define folder browse dialog
Dim Dialog = New FolderBrowserDialog()

' Set options for folder browser dialog
Dialog.SelectedPath = ExportPath
Dialog.ShowNewFolderButton = True
Dialog.Description = "Choose Folder for Export..."

' Show dialog box
If DialogResult.OK = Dialog.ShowDialog() Then
    ' User clicked 'ok' on dialog box - capture the export path
    ExportPath = Dialog.SelectedPath & "\"
    
Else
    ' User clicked 'cancel' on dialog box - exit
    Return
End If
oFileName = iProperties.Value("Custom", "Sales Order Number")

' Define the filename of the file to be exported - in this case it is a PDF file extension
ExportFilename = oFileName & ".pdf"

' Do export operation (using save as)
Try
    ThisDoc.Document.SaveAs(ExportPath & ExportFilename, True)
Catch
    MsgBox("File export failed...", 64, "Formsprag iLogic")
End Try

' Ask user if they want to open (launch) the file we just exported...
If MsgBox("File exported: " & _
        ExportPath & ExportFilename & vbLf & vbLf & _
        "Do you want to open the PDF Now?", 36, "Formsprag iLogic - File Exported") = 6 Then
    ' User says yes...launch exported file
    ThisDoc.Launch(ExportPath & ExportFilename)
End If

 Thanks in advance

3 REPLIES 3
Message 2 of 4

 

Hi Formsprag,

 

Here is the combined code. 

 

Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too, and that's probably the better place for them:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

' This is an example iLogic rule by Luke Davenport on Cadline Community
' It creates a 'folder browser dialog' to allow user to pick a directory location
' This selected directory location is then used for a generic PDF export operation
' Please modify to suit your requirements....

Imports System.Windows.Forms
    
' Get current location of this file
Dim ExportPath As String = ThisDoc.Path

' Check that this file has been saved and actually exists on disk
If String.IsNullOrEmpty(ExportPath) Then
    MsgBox("This file has not yet been saved and doesn't exist on disk!" _
	& vbLf & "Please save it first",64, "Formsprag iLogic")
Return
End If

' Define folder browse dialog
Dim Dialog = New FolderBrowserDialog()

' Set options for folder browser dialog
Dialog.SelectedPath = ExportPath
Dialog.ShowNewFolderButton = True
Dialog.Description = "Choose Folder for Export..."

' Show dialog box
If DialogResult.OK = Dialog.ShowDialog() Then
    ' User clicked 'ok' on dialog box - capture the export path
    ExportPath = Dialog.SelectedPath & "\"    
Else
    ' User clicked 'cancel' on dialog box - exit
    Return
End If

oFileName = iProperties.Value("Custom", "Sales Order Number")

' Define the filename of the file to be exported
' In this Case it Is a PDF file extension
ExportFilename = oFileName & ".pdf"

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

'set PDF Options
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
End If

'Set the PDF target file name
oDataMedium.FileName = ExportPath & ExportFilename

Try 
	'Publish document
	oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
Catch
	MessageBox.Show("Error writing out PDF", "iLogic")
	bError = True
End Try

If bError <> True Then
	'Ask user If they want To open (launch) the file we just exported...
	oMessage = "File exported: " & _
			ExportPath & ExportFilename & vbLf & vbLf & _
			"Do you want to open the PDF Now?"
			
	oQuestion = MessageBox.Show(oMessage, _
	"Formsprag iLogic - File Exported",MessageBoxButtons.YesNo)
	
	If oQuestion = vbYes Then
		ThisDoc.Launch(ExportPath & ExportFilename)
	End If

End If
Message 3 of 4

Thank you, I will use the Inventor Customization forum from now on!

Message 4 of 4
Anonymous
in reply to: Curtis_Waguespack

Hi I am Novice in here and just migrating from longtime solidedge to Inventor.


I used the above code but with little variation in which i wanted to use a custom property instead of sales order I wanted to use it with the file name. So I used this code 

Solved: Filename into custom iproperty - Autodesk Community - Inventor

 

But I am getting error. 

System.NullReferenceException: Invalid pointer (Exception from HRESULT: 0x80004003 (E_POINTER))
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

As I am very fresh to the ilogic side.. my brain is not ready to process the coding stuff. 

So help needed.. 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report