Error on ModelState.Activate()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have something strange with Assemblies with ModelStates.
OnEvent OnOpenDocument starts a piece of iLogic-code. This code Checks for Writability, Tries to get the FactoryDocument, creates (if not exists) some iProperties and Paramaters, and then loop through each ModelState checking and/or updating some Values for above mentioned iProperties and Parameters... So far, so good.
When I have this Assembly open and checked out in Inventor the code runs flawless. Problem occurs when I OpenFromVault as ReadOnly. The Rule is triggered by OnOpenDocument Event and Exits again quickly if it determines that the Document is not Writable.
At the time of CheckOut from the Vault browser in Inventor the Event OnOpenDocument gets triggered again and the Rule errors out ((Exception from HRESULT: 0x80004005 (E_FAIL))) on Activating the first (Primary) ModelState. I did not get any useful info with this error message.
If (oModelStates IsNot Nothing) AndAlso (oModelStates.Count <> 0) Then
Logger.Trace("Start looping through Model States running sub-routines")
' Store current Model State and MemberEditScope
Dim oCurrentModelState As ModelState = oModelStates.ActiveModelState
Dim oCurrentMemberEditScope As MemberEditScopeEnum = oModelStates.MemberEditScope
If (oModelStates.MemberEditScope <> MemberEditScopeEnum.kEditActiveMember) Then oModelStates.MemberEditScope = MemberEditScopeEnum.kEditActiveMember
For Each oModelState As ModelState In oModelStates
Logger.Trace("oDoc is: " & oDoC.FullDocumentName)
If oDoC.IsModifiable = False Then
Logger.Trace(oDoC.FullDocumentName & " is not Modifiable")
Continue For
End If
If oDoC.RequiresUpdate = True Then
Logger.Trace(oDoC.FullDocumentName & " Requires an Update")
oDoC.Update2
End If
Logger.Trace("Try to activate ModelState " & oModelState.Name & " te activeren...")
oModelState.Activate()
Logger.Trace("After activating ModelState " & oModelState.Name)
'ArticleNumber(oDoC)
'MaterialProperties(oDoC)
'PhysicalProperties(oDoC)
'ThicknessParameters(oDoC, oSubType)
Logger.Trace("Next ModelState")
Next
' Reset Model State and MemberEditScope to previous value
If (oModelStates.ActiveModelState IsNot oCurrentModelState) Then oCurrentModelState.Activate
If (oModelStates.MemberEditScope <> oCurrentMemberEditScope) Then oModelStates.MemberEditScope = oCurrentMemberEditScope
Else
Logger.Trace("No Model States, just run sub-routines...")
ArticleNumber(oDoC)
MaterialProperties(oDoC)
PhysicalProperties(oDoC)
ThicknessParameters(oDoC, oSubType)
DrawingProperties(oDoC, oSubType)
End If
Another thing I notice is that ThisDoc.FactoryDocument.FullDocumentName returns a DcumentName with <ModelState Name>. This while I was under the impression that the FactoryDocument was the base document. So I actually expected DocumentName or DocumentName <[Primary]>. This is general behavior by the way (not different from the two situations mentioned above).
Any ideas what could be going on here and how I can catch or prevent this error?
No Substitutes involved...
//Edit// When the document is saved with ModelStates.MemberEditScope = kEditAllMembers the error moves to line 5-6 with the MemberEditScope.
Using Inventor 2023.5.1
René van der Starre