If you turn defer updates on, Inventor blocks all kinds of editability, to the in-memory data. But the file itself stays as is, so that is what I use for read-only processing, where I only want to read from the file, and not modify it.
Here is my complex open file tool that I use with many different scenarios (vb.net written in vs 2015-2019):
Public Function OpenInventorFile(fileinfo As SIO.FileInfo, Optional Deferred As Boolean = False, Optional Hidden As Boolean = False, ByRef Optional FileOpened As Boolean = False) As Inventor.Document
If fileinfo.Exists = False Then Return Nothing
Dim invDoc As Inventor.Document = Nothing
Dim invApp As Inventor.Application = TTSInventorTools.GetInventorApplication()
Try
If invApp IsNot Nothing Then
'open document
Try 'find open document
'invDoc = invApp.Documents.ItemByName(fileinfo.FullName)
For Each doc As Inventor.Document In invApp.Documents
If doc.FullFileName = fileinfo.FullName Then
invDoc = doc
Exit For
End If
Next
'invDoc.Save()
Catch ex As Exception
'open file by name
End Try
If invDoc Is Nothing OrElse Hidden = False Then
If Deferred = True Then
Dim docOpenOptions As NameValueMap
docOpenOptions = invApp.TransientObjects.CreateNameValueMap
docOpenOptions.Add("SkipAllUnresolvedFiles", True)
If fileinfo.Extension = ".idw" Then docOpenOptions.Add("DeferUpdates", True)
Dim silentPrev As Boolean = invApp.SilentOperation
invApp.SilentOperation = True
If Hidden = True Then
invDoc = invApp.Documents.OpenWithOptions(fileinfo.FullName, docOpenOptions, False)
FileOpened = True
Else
invDoc = invApp.Documents.OpenWithOptions(fileinfo.FullName, docOpenOptions, True)
FileOpened = True
End If
invApp.SilentOperation = silentPrev
Else
Dim docOpenOptions As NameValueMap
docOpenOptions = invApp.TransientObjects.CreateNameValueMap
docOpenOptions.Add("SkipAllUnresolvedFiles", True)
If Hidden = True Then
invDoc = invApp.Documents.OpenWithOptions(fileinfo.FullName, docOpenOptions, False)
FileOpened = True
Else
invDoc = invApp.Documents.OpenWithOptions(fileinfo.FullName, docOpenOptions, True)
FileOpened = True
End If
End If
End If
If invDoc Is Nothing Then
FileOpened = False
Throw New Exception("Attempt to open file failed:" & fileinfo.FullName)
End If
End If
Catch ex As Exception
Dim eh As New ErrorHandler(New System.Exception("Can not open file:" & fileinfo.FullName & vbCr & ex.Message))
eh.HandleIt()
End Try
Return invDoc
End Function
Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/