04-16-2015
07:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
04-16-2015
07:14 AM
Here is a program I wrote that will print to PDF using a programatic file name - Yes, this is a huge work-around, but it works!
NOTE: You must change the PDF print output in preferences to Print To Specified Output Folder (which should be an empty folder solely for the purpose of this program), and then add that to the program at the top instead of what I have there.
Imports System
Imports System.IO
Sub Main()
Dim oOutputFolder As String = "C:\Users\Rob\Desktop\ADOBE PRINT OUTPUT\"
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim oStr As String
Dim oStr1 As String
Dim FNamePos As String
If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject
Else
MsgBox("Use A Drawing Document, Dummy.")
Exit Sub
End If
Dim j As Integer: j=1
Dim k As Integer: k=1
k=InputBox("What Sheet Count Do You Want To Start On?", "Sheet Start", 1)
Dim oTargetDir As String = oFolderDlg
If oTargetDir = ""
Exit Sub
End If
For j=k To oDoc.Sheets.Count
oSheet=oDoc.Sheets.Item(j)
oSheet.Activate
FNamePos = InStrRev(oSheet.Name, ":", - 1)
oStr1 = Left(oSheet.Name, FNamePos-1)
oStr = iProperties.Value("Custom", "WO#") & "-" & oStr1
oTarget = oTargetDir & "\" & oStr & ".pdf"
Dim oCheck() As String
oCheck = System.IO.Directory.GetFiles(oOutputFolder)
If (oCheck IsNot Nothing And oCheck.Length>0)
MsgBox("PDF Output Had A File In It. Aborting Rule",, "RULE OVERRIDE")
Exit Sub
End If
oPDFPrint
Threading.Thread.Sleep(30)
If oMove(oOutputFolder, oTarget) = 0
MsgBox("Program Aborted",,"Program Notice")
Exit Sub
End If
Next
MsgBox("Program Ran Successfully",, "Success Message")
End Sub
Function oFolderDlg
Dim dialog = New System.Windows.Forms.FolderBrowserDialog()
' dialog.SelectedPath = Application.StartupPath
dialog.ShowNewFolderButton = True
' openFileDialog1.InitialDirectory
If System.Windows.Forms.DialogResult.OK = dialog.ShowDialog() Then
oPath = dialog.SelectedPath
Else
MsgBox("No File Selected. Aborting Rule")
oPath = ""
End If
Return oPath
End Function
Sub oPDFPrint
Dim oDrgPrintMgr As DrawingPrintManager
Dim oDrgDoc As DrawingDocument
ThisApplication.SilentOperation = True 'Must Be Set to False at End.
oDrgDoc = ThisApplication.ActiveDocument
oDrgPrintMgr = oDrgDoc.PrintManager
oDrgPrintMgr.Printer = "Adobe PDF"
oDrgPrintMgr.ScaleMode = kPrintBestFitScale
oDrgPrintMgr.PaperSize = kPaperSize11x17
'oDrgPrintMgr.PaperSize =kPaperSizeLetter
oDrgPrintMgr.PrintRange = kPrintCurrentSheet
oDrgPrintMgr.NumberOfCopies = 1
oDrgPrintMgr.Orientation = kLandscapeOrientation
oDrgPrintMgr.AllColorsAsBlack = True
oDrgPrintMgr.RemoveLineWeights = False
oDrgPrintMgr.SubmitPrint
ThisApplication.SilentOperation = False
End Sub
Function oMove(oOutputFolder As String, oTarget As String) As Integer
Dim watch As Stopwatch = Stopwatch.StartNew()
Dim watch2 As Stopwatch = Stopwatch.StartNew()
Dim oFile() As String
Dim r As String = 1
Dim oLimit As Boolean = True
Dim oAsk As Boolean = True
''Move this to the printing code up a level.
While watch.Elapsed.TotalMilliseconds < 15000 And oLimit = True
While watch2.Elapsed.TotalMilliseconds < 2000 And oLimit = True
oFile= System.IO.Directory.GetFiles(oOutputFolder, "*.pdf")
If (oFile IsNot Nothing And oFile.Length>0)
oLimit = False
System.IO.File.Move(oFile(0), oTarget)
Else
If oAsk = True
r=MsgBox("Keep Waiting For PDF to Print?", MsgboxStyle.OkCancel, "Dialog")
If r = MsgBoxResult.Cancel
MsgBox("You don't like waiting, eh? Bye then.",, "Exit Message")
Return 0
Exit Function
Else
oAsk=False
watch2.Reset
watch2.start
End If
End If
End If
End While
oAsk = True
watch2.Reset
watch2.start
End While
If oLimit = True
MsgBox("Program Stopped - Over time",, "Failure Message")
End If
watch.Stop()
watch2.Stop()
Return 1
End Function
--------------------------------------
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
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
Solved! Go to Solution.
04-16-2015
07:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
04-16-2015
07:17 AM
Please Kudos/Comment if you end up using this, just so I know if there is a point to sharing programs on here,
Thanks!
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Thanks!
--------------------------------------
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
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