By Barbara Han
Issue
I am trying to put watermark on the Inventor File while check-in to the vault inside Inventor. I am doing this in the "Pre-Check-in event", but, the file is getting prompted to be checked out. Is it possible to change my file while check-in command is invoked?
Solution
In this case, the pre event of the web service API, i.e. CheckinFile, is triggered after the file is read by Vault Addin and set to read only, so it's too late to change the file at this moment.
The way is to capture command event, i.e. UserInputEvents.OnActivateCommand, through Inventor API. This event should fire before pre event of the CheckinFile API. If the command name is, i.e. VaultCheckinTop (you can specify other command, of course), you can edit the file and save it, then the change will be saved in Vault file.
The following is a VB.NET sample code that capture the command event from an Inventor AddIn, and add a work point in part file while checking the part file in Vault:
Dim UIEvts As UserInputEvents = m_inApp.CommandManager.UserInputEvents
AddHandler UIEvts.OnActivateCommand, AddressOf UIEvts_OnActivateCommand
……
Private Sub UIEvts_OnActivateCommand(ByVal CommandName As String, ByVal Context As NameValueMap)
If CommandName = "VaultCheckinTop" Then
Dim curDoc As Document = m_inApp.ActiveDocument
If curDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim ptDoc As PartDocument = curDoc
Call ptDoc.ComponentDefinition.WorkPoints.AddFixed(m_inApp.TransientGeometry.CreatePoint(10, 10, 100))
ptDoc.Save()
End If
End If
End Sub
Actually this method should work with AutoCAD too, but the command event and command name may be different between Inventor and AutoCAD. For AutoCAD, you can capture Document.CommandWillStart event with AutoCAD .NET API, or AcEditorReactor.commandWillStart event with ObjectARX API.