I LOGIC rule pdf export

I LOGIC rule pdf export

Anonymous
Not applicable
519 Views
3 Replies
Message 1 of 4

I LOGIC rule pdf export

Anonymous
Not applicable

Anyone have a simple I logic rule to export PDF. The rules I have tried to use have not worked. I currently use a rule to export dxf and print - I now need to add some more code to the end of my dxf rule to export Pdf files. No need for batch print.

 

Any help will be greatly appreciated!

0 Likes
520 Views
3 Replies
Replies (3)
Message 2 of 4

MechMachineMan
Advisor
Advisor

Here is one that exports PDFs. (If you want a flattened file, you should be passing the file to a PDF Printer instead of exporting it thorugh the add-in.)

 

	Sub ExportPDF(oDwgDocString As String)
	
		Dim oDwgDoc As DrawingDocument
		oDwgDoc = ThisApplication.Documents.Open(oDwgDocString) 
	
		Dim oPDFAddIn As TranslatorAddIn
		oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	
		Dim oContext As TranslationContext
		oContext = ThisApplication.TransientObjects.CreateTranslationContext
		oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	
		Dim oOptions As NameValueMap
		oOptions = ThisApplication.TransientObjects.CreateNameValueMap
		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
		
		Dim oDataMedium As DataMedium
		oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
		oDataMedium.FileName = "C:\Users\Owner\Desktop\PDF\" & System.IO.Path.GetFileNameWithoutExtension(oDwgDoc.FullFileName) & ".pdf"
	
		Call oPDFAddIn.SaveCopyAs(oDwgDoc, oContext, oOptions, oDataMedium)
		
		oDwgDoc.Close(False)
	End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 4

Anonymous
Not applicable

I keep getting this error "All other Sub's or functions must be after Sub Main()"

 

I can use the code below - however I would like to control where it saves the file with the rule I don't know how to add a path to the rule.

 

 

oDoc = ThisApplication.ActiveDocument
sFname = ThisDoc.PathAndFileName(False) & ".PDF"
oDoc.SaveAs(sFname, True)

 

0 Likes
Message 4 of 4

MechMachineMan
Advisor
Advisor

Here is revised as per your needs.

 

The error is because the rule environment always tries to run "Sub Main()" first, and if it doesn't find it, it errors out.

 

From Sub Main you can call other subs to really modularize your programming.

The reason it was ExportPDF(DwgDocString) was for exactly that reason; the sub that called it organized the batch printing aspect of the program.

 

 

	Sub Main()
	
		Dim oDwgDoc As DrawingDocument
Try oDwgDoc = ThisApplication.ActiveDocument Catch
MsgBox("Valid for drawing Documents only!")
End Try
Dim oPDFAddIn As TranslatorAddIn oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap 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 Dim oDataMedium As DataMedium oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

' The single line below this is all you need to tweak to select the filename. ie; right now it prints to a folder on my desktop oDataMedium.FileName = "C:\Users\Owner\Desktop\PDF\" & System.IO.Path.GetFileNameWithoutExtension(oDwgDoc.FullFileName) & ".pdf" Call oPDFAddIn.SaveCopyAs(oDwgDoc, oContext, oOptions, oDataMedium) oDwgDoc.Close(False) End Sub

 

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes