By Adam Nagy
It seems that in Inventor 2016 the behaviour of IsFileInActiveProject has been modified in a way that now it triggers the OnFileResolution event. Which of course means that if you are calling IsFileInActiveProject from inside OnFileResolution then you are creating an endless loop that will bring Inventor down.
I'm not sure yet if this change in behaviour is by-design or not, but it could be. I can imagine that now we allow add-ins to chip in when finding files even in case of using IsFileInActiveProject.
In order to avoid the endless loop, you just need to use a flag variable to signal if OnFileResolution has been called as a result of IsFileInActiveProject or not. Here is my VBA clsEvents class that shows what I mean:
Dim WithEvents faEvents As FileAccessEvents ' To avoid recursion Private inside As Boolean Private Sub Class_Initialize() Set faEvents = ThisApplication.FileAccessEvents inside = False End Sub Private Sub faEvents_OnFileResolution( _ ByVal RelativeFileName As String, _ ByVal LibraryName As String, _ CustomLogicalName() As Byte, _ ByVal BeforeOrAfter As EventTimingEnum, _ ByVal Context As NameValueMap, _ FullFileName As String, _ HandlingCode As HandlingCodeEnum) Dim str As String Dim loc As LocationTypeEnum ' To avoid recursion we use a flag variable ' called "inside" If Not inside Then inside = True Dim dpm As DesignProjectManager Set dpm = ThisApplication.DesignProjectManager Call dpm.IsFileInActiveProject( _ "1.ipt", _ loc, _ str) inside = False HandlingCode = HandlingCodeEnum.kEventHandled End If End Sub