HELP!!! Automated Inventor Drawing Release Process Using iLogic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
My company will be starting a hybrid work schedule and we are looking for a way to automate our drawing release process. Currently in house when a drawing is ready to be released we print a physical copy of the drawing and use a physical stamp to stamp the drawing with a signature, job number, date and rev number. After stamped the drawing is scanned and placed into vault next to the live inventor drawing and the physical print is handed off to fab. If that drawing gets revised the corrections are made and the drawing is printed again and goes through the same process again and the scan is checked into vault over the previous rev to retain history. The revised drawing will also have an additional stamp added to it to indicate that it was revised and previous physical prints need to be destroyed.
With the new hybrid schedule we are looking for an automated electronic way of capturing this release process. Ultimately I would like to have a single click button that once pressed will either swap out the drawing border for a nearly identical border with "approved for fab" and some prompted entry text for signature, date, time, job # and rev. or just have the code place a stamp on the drawing with the same prompted entry info. After that info is filled out the code would automatically print a hard copy and make a pdf that's saved next to the live file (if we can get this far the next step would be to have that pdf actually saved in a sub folder in the parent file directory and checked into vault) Once the pdf file is created and saved it would revert the actual inventor drawing back to its original state without the "approved for fab" border and info on it and save and check in the file.
To complicate it a little more, when entering the "approved for fab" info, if a rev is entered that is anything other than a blank or a "0" it would put yet a different border or additional static stamp on the drawing that basically says its a revised drawing and previous revs (printed hard copies) need to be destroyed.
My guess would be the hardest part of all of this would be the checking in to vault of the pdf file and if that's not doable I would be ok with a message that pops up that tells the user to put the pdf file in vault.
I found some border swap code that I was playing around with but have yet to be able to get it to work, I am not good with iLogic/vba and below are the codes that we currently use for printing and making pdf's. If someone is able to help me get this all to work that would be great and much appreciated. Other ideas/utilities are welcomed also if there is something else out there that would do what we are looking for.
Here is my code currently for pdf's:
Sub Main iProperties.Value("Custom", "PlotDate&Time") = Now.ToString() Dim oDrgDoc As DrawingDocument oDrgDoc = ThisApplication.ActiveDocument ' Set reference to drawing print manager' DrawingPrintManager has more options than PrintManager' as it's specific to drawing document Dim oDrgPrintMgr As DrawingPrintManager oDrgPrintMgr = 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.kPrintCustomScale oDrgPrintMgr.ScaleMode = PrintScaleModeEnum.kPrintBestFitScale 'oDrgPrintMgr.PaperSize = PaperSizeEnum.kPaperSizeLedger oDrgPrintMgr.PaperSize = PaperSizeEnum.kPaperSize11x17 'oDrgPrintMgr.PaperSize = 14338 oDrgPrintMgr.PrintRange = PrintRangeEnum.kPrintAllSheets oDrgPrintMgr.Orientation = kLandscapeOrientation 'oDrgPrintMgr.PaperSource = 2 oDrgPrintMgr.AllColorsAsBlack = False Dim pdfFileName = 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 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 = Path.GetDirectoryName(fileName) Dim tempName = Path.Combine(folderName, System.Guid.NewGuid().ToString() + ".txt") Try File.WriteAllText(tempName, "test") 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
And here is my code currently for printing:
'check for custom iprops and add them if not found Dim propertyName1 As String = "CurrentUser" Dim propertyName2 As String = "PlotDate&Time" customPropertySet = ThisDoc.Document.PropertySets.Item _ ("Inventor User Defined Properties") Try prop = customPropertySet.Item(propertyName1) prop = customPropertySet.Item(propertyName2) Catch ' Assume error means not found customPropertySet.Add("", propertyName1) customPropertySet.Add("", propertyName2) End Try 'output the custom iproperties and update the file RuleParametersOutput() InventorVb.DocumentUpdate() '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 & " " & Time 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 '[ Dim oDrgDoc As DrawingDocument oDrgDoc = ThisApplication.ActiveDocument ' Set reference to drawing print manager' DrawingPrintManager has more options than PrintManager' as it's specific to drawing document Dim oDrgPrintMgr As DrawingPrintManager oDrgPrintMgr = 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 = kCustomScale 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 ']