Add Stamp or Change drawing border with ilogic???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Below I have combined code for creating a pdf and printing and drawing. I need to add code to do a border swap with prompted entry text and then after creating the pdf and printing revert the border back to the original. So ideally I would run the rule and it would switch to a border with prompted entry text for Signature, Date, Job No, and Rev. The user would fill out that info and then the rule would continue and create the pdf and then print, after that the border would revert back to the original. Also it would be nice if during the prompted text entry, if a rev is entered that is anything other than a "blank, zero or an A" the code would add an additional static stamp onto the drawing as another visual indicator that the drawing has been revised.
If a border swap isn't doable just adding a stamp with the prompted entry text before pdf and printing would work as well but would still need the additional static stamp if an additional rev is entered. Then after pdf and printing the code would remove the stamps.
Edit: The more I think about it, it would probably make more sense to use a stamp instead of swapping out drawing borders because the drawing templates we use vary.
Option Explicit On Imports System.IO
Sub Main CreatePDF() Printing() End Sub Sub CreatePDF() Dim oDrgDoc As DrawingDocument = ThisDoc.Document iProperties.Value("Custom", "PlotDate&Time") = Now.ToString() ' Set reference to drawing print manager' DrawingPrintManager has more options than PrintManager' as it's specific to drawing document Dim oDrgPrintMgr As DrawingPrintManager = oDrgDoc.PrintManager Dim pdfname = ThisDoc.FileName(False) Dim filePath = ThisDoc.Path ' Set the printer name' comment this line to use default printer or assign another one oDrgPrintMgr.Printer = "Microsoft Print To PDF" 'Set the paper size , scale and orientation oDrgPrintMgr.ScaleMode = PrintScaleModeEnum.kPrintBestFitScale oDrgPrintMgr.PaperSize = PaperSizeEnum.kPaperSize11x17 oDrgPrintMgr.PrintRange = PrintRangeEnum.kPrintAllSheets oDrgPrintMgr.Orientation = kLandscapeOrientation 'oDrgPrintMgr.PaperSource = 2 oDrgPrintMgr.AllColorsAsBlack = False Dim pdfFileName = System.IO.Path.Combine(filePath, pdfname + ".pdf") If Not CanSaveToFile(pdfFileName) Then MessageBox.Show("Folder or file is read only", "Save PDF") Dim oFileDlg As Inventor.FileDialog Call ThisApplication.CreateFileDialog(oFileDlg) oFileDlg.FilterIndex = 1 oFileDlg.DialogTitle = "Save file" 'oFileDlg.InitialDirectory = oFileDlg.CancelError = False oFileDlg.FileName = pdfname + ".pdf" Call oFileDlg.ShowSave() pdfFileName = oFileDlg.FileName If String.IsNullOrEmpty(pdfFileName) Then Logger.Info("No file specified") Return End If End If oDrgDoc.SaveAs(pdfFileName, True) End Sub Sub Printing() Dim oDrgDoc As DrawingDocument = ThisDoc.Document 'Plot Stamp 'Applies current filename & path, Date & time, and current user stamp to edge of border to be printed with the drawing '[ iProperties.Value("Custom", "PlotDate&Time") = Now iProperties.Value("Custom", "CurrentUser") = System.Security.Principal.WindowsIdentity.GetCurrent.Name InventorVb.DocumentUpdate() 'Dim oCtrlDef As ControlDefinition 'oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppFilePrintCmd") 'oCtrlDef.Execute '] 'Print Setup '[ ' Set reference to drawing print manager' DrawingPrintManager has more options than PrintManager' as it's specific to drawing document Dim oDrgPrintMgr As DrawingPrintManager = oDrgDoc.PrintManager ' Set the printer name' comment this line to use default printer or assign another one 'oDrgPrintMgr.Printer = "\\kcidc2012\EngineeringSharp_Ledger" 'oDrgPrintMgr.Printer = "EngineeringSharp_Ledger" 'oDrgPrintMgr.Printer = "\\kcidc2012\EngineeringSharp_Ledger_Color" oDrgPrintMgr.Printer = "\\kcipdc2019\Engineering_Ledger_Color" 'Set the paper size , scale and orientation 'oDrgPrintMgr.ScaleMode = PrintScaleModeEnum.kPrintCustomScale oDrgPrintMgr.ScaleMode = PrintScaleModeEnum.kPrintBestFitScale 'oDrgPrintMgr.PaperSize = PaperSizeEnum.kPaperSizeLedger 'oDrgPrintMgr.PaperSize = PaperSizeEnum.14338 'oDrgPrintMgr.PaperSize = PaperSizeLedger oDrgPrintMgr.PrintRange = kPrintCurrentSheet oDrgPrintMgr.Orientation = kLandscapeOrientation oDrgPrintMgr.PaperSource = 2 oDrgPrintMgr.AllColorsAsBlack = False oDrgPrintMgr.SubmitPrint '] End Sub Function CanSaveToFile(fileName As String) Dim FileInfo As New FileInfo(fileName) If FileInfo.Exists Then If FileInfo.IsReadOnly Then Return False ElseIf FileIsLocked(FileInfo) Then ' We can't write to it. It might be open in Adobe Acrobat Reader Return False End If End If ' make sure we can write to the directory Dim folderName = System.IO.Path.GetDirectoryName(fileName) Dim tempName = System.IO.Path.Combine(folderName, System.Guid.NewGuid().ToString() + ".txt") Try System.IO.File.WriteAllText(tempName, "test") System.IO.File.Delete(tempName) Catch Return False End Try Return True End Function ' from https://stackoverflow.com/questions/876473/is-there-a-way-to-check-if-a-file-is-in-use Function FileIsLocked(FileInfo As FileInfo) As Boolean Dim Stream As FileStream = Nothing Try Stream = FileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.None) Catch ex As IOException 'the file is unavailable because it is: 'still being written To 'or being processed By another thread 'or does Not exist (has already been processed) Return True Finally If (Stream IsNot Nothing) Then Stream.Close() End If End Try Return False End Function