We can create an ActiveX executable, which references the ApprenticeServer API, and which also exposes a suitable API of its own. We can then call into our ActiveX executable from an Inventor AddIn dll to request updates to any file references.
So - as a minimum, the API exposed by our ActiveX executable should allow us to open an Inventor document, update any file references, then save the updated document.
Here are the steps we need to perform in our server:-
(1) Create an Apprentice Server object
(2) Open an Inventor document via the Apprentice Server API
(3) Update relevant file references
(4) Save the modified document
(5) Destroy the Apprentice Server object.
The code sample sample below does exactly this (with the restriction that only Assembly documents can be updated). When an instance of the ActiveX component is initialized, an ApprenticeServerComponent is automatically created.
Then we call the 'OpenAssembly()' method passing in the path to an Assembly file.
Next we call the 'Update()' method - passing in a path to a referenced file that is to be updated, along with the new path.
Once all paths have been updated, we call the 'Save()' method to save our updated file references in the Assembly document.
The ApprenticeServerComponent object is automatically destroyed as our ActiveX server terminates.
To use our Server we firstly need to add a reference to it from our Inventor AddIn project (I've called it 'FileRefUpdater'), then we just add code to call the API we have exposed.
' The path to our Assembly document
Dim sAsmDocPathName As String = ".........."
Dim oFileRefUpdater As Object
oFileRefUpdater = CreateObject("FileRefUpdater.clsFileRefUpdater") ' create our Server
' and open the Assembly document
Dim sOldPath As String
sOldPath = "......" ' the path to a file that is being moved
Dim sNewPath As String
sNewPath = "....." ' the updated location.
System.IO.File.Move(sOldPath, sNewPath) ' move the document
' update the references in our Assembly
oFileRefUpdater.Save() ' and save
oFileRefUpdater = Nothing ' all done!