HELP!!! Automated Inventor Drawing Release Process Using iLogic

HELP!!! Automated Inventor Drawing Release Process Using iLogic

Jason.Rugg
Collaborator Collaborator
757 Views
9 Replies
Message 1 of 10

HELP!!! Automated Inventor Drawing Release Process Using iLogic

Jason.Rugg
Collaborator
Collaborator

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
']

 

 

0 Likes
758 Views
9 Replies
Replies (9)
Message 2 of 10

JelteDeJong
Mentor
Mentor

I think that all you want to do is possible with the Autodesk Vault and the lifecycles in vault. Did you consider using vault?

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 10

Jason.Rugg
Collaborator
Collaborator

@JelteDeJong We only have Vault Basic with no plans to move to Pro.

0 Likes
Message 4 of 10

A.Acheson
Mentor
Mentor

This is all fairly simple stuff individually although it is alot of process your rolling into one. The vault piece may be the more difficult piece.

A few things

  • Stamp would likely be a promted entry symbol placed on the drawing. I have yet to see an automated pdf stamp. 
  • Anything connected to the title block/border would be best to have straight iproperty population. Avoid if you can swapping them out unless there contain different data. It will be easier later for any changes if you have less to modify. Avoid if possible using prompted entry in the title block unless that is used allready in your company. Passing data through prompted entry can be extremely challenging.
  • The workflow is obviously very custom to your company so I would suggest for yourself to create a number list of all the process as they will likely become sub routines later. Then test those sub routines in there own rule or isolated to ensure they function correctly. If they don't then post the issues along with the code for requesting assistance if needed. 
  • In the code you have posted where or what are the issues your seeing? Can you post the error messages? Without the specific drawing template it will likely be difficult to test this. So it may be best to supply a test drawing with some sample data for testing along with the inventor version your using. 
  • How are you displaying/inputting the data into to the drawing for the user? Via an ilogic global form/vba form or other? 
If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 10

A.Acheson
Mentor
Mentor

Here is my attempt to adjust what you presented to be more modular and reusable. The following errors were what came up when checking the code. adding Imports System.IO to the header and specifically writing System.IO solved a lot. I removed the iProperty addition through the API's property set as the ilogic snippet will do this automatically.

 

AAcheson_0-1661486369175.pngAAcheson_1-1661486388396.png

 

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

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 6 of 10

To_Efficiency_and_Beyond
Enthusiast
Enthusiast

I am going to give one of those answers that might be the most useless thing for you or a complete game changer... I apologize if it is the former!

 

You can modify inventor to fit your workflow, or you can modify your workflow to fit inventor. The process you are describing sounds like you are forcing Inventor to support a very unusual workflow. I find that (very generally speaking) the absolute best results happen when you reimagine the workflow from the ground up. You (or your company) have chosen to use Inventor, so create workflows that function very naturally with Inventor, then modify Inventor a bit to make the whole process fit your company perfectly. It is shocking when you realize how much time/stress/mistakes can be saved when this is applied properly! Food for thought 🙂

Message 7 of 10

Jason.Rugg
Collaborator
Collaborator

@A.Acheson That worked well, now if the border swap and prompted entry text could be done before pdf and printing that would be great. Is that doable?

 

So first swap to a different border with prompted entry text, then make the pdf and print, after that swap the border back to the original. Also as I described in my original post, in the prompted entry text if a rev is entered that is anything other than a blank or a zero it would place a static stamp on the drawing to indicate that it is a revised drawing, then do the pdf and print.

0 Likes
Message 8 of 10

A.Acheson
Mentor
Mentor

Here is the VBA sample for adding a custom border and setting prompted entry. It is already set up in a sub routine called “InsertCustomBorderOnSheet”. You will need to convert to ilogic by removing the word “Set”. You said in the original post that you had some ode for doing this that you had worked on perhaps you can provide them if they are partially working. Tweaking a few lines can be better than sourcing whole blocks of code and there is more chance of learning as you are more familiar with what you have  attempted a modification on. Also the if you poke around the samples you will get one for a revision block query.

 

Without seeing a sample drawing or images a lot  of what is required is just guess work as there is many ways company display the data. 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 9 of 10

Jason.Rugg
Collaborator
Collaborator

@A.Acheson After thinking about it I think it would be better to just add a stamp with prompted entry rather than swapping out borders just because our templates vary. Though I guess it wouldn't really matter if the borders were different but used the same name across templates. The end goal is still the same, enter the information, then pdf and print, then remove the stamp(s). I was also thinking instead of trying to detect if a certain rev has been entered or not, just have a box pop up and asked if it is a revised drawing and if "yes" it would place the additional stamp, pdf and print, and then delete the stamps. Hopefully this simplifies things.

0 Likes
Message 10 of 10

lgannonV3P7N
Explorer
Explorer

You could have different title blocks that have the iproperties you need as a watermark across the sheet, swap title blocks then swap back? Could also add/remove border with this? 

Sub Main()

'Can remove this check

If ThisApplication.ActiveDocument Is Nothing Or ThisApplication.ActiveDocumentType <> kDrawingDocumentObject Then
    MsgBox ("Please open a Drawing to work on.")
    Exit Sub
End If

'Clear existing title block

Dim oDrawingDoc As Document = ThisApplication.ActiveDocument
For SheetNumber = 1 To oDrawingDoc.Sheets.Count
    oDrawingDoc.Sheets(SheetNumber).Activate
    If Not oDrawingDoc.ActiveSheet.TitleBlock Is Nothing Then
        oDrawingDoc.ActiveSheet.TitleBlock.Delete
    End If
Next SheetNumber


    If  iProperties.Value("Project","Revision Number") = R1 Then
	For SheetNumber = 1 To oDrawingDoc.Sheets.Count
	oDrawingDoc.Sheets(SheetNumber).Activate
   	 ActiveSheet.TitleBlock = "INTERNAL R1"
	 ActiveSheet.Border="New Border"
	Next SheetNumber
    End If
	
    If  iProperties.Value("Project","Revision Number") <> R1 Then
	For SheetNumber = 1 To oDrawingDoc.Sheets.Count
	oDrawingDoc.Sheets(SheetNumber).Activate
   	 ActiveSheet.TitleBlock = "INTERNAL R2"
	 ActiveSheet.Border="New Border"
	Next SheetNumber
    End If

'Call Functions	
Create PDF()
Printing()

'Delete Updated Title block	
For SheetNumber = 1 To oDrawingDoc.Sheets.Count
    oDrawingDoc.Sheets(SheetNumber).Activate
    If Not oDrawingDoc.ActiveSheet.TitleBlock Is Nothing Then
        oDrawingDoc.ActiveSheet.TitleBlock.Delete
    End If
   'Add old title block/border
   ActiveSheet.TitleBlock = "Original"
   ActiveSheet.Border="Default Border"
   Next SheetNumber


End Sub

 

0 Likes