Error on ModelState.Activate()

Error on ModelState.Activate()

PolemEngineering
Advocate Advocate
184 Views
1 Reply
Message 1 of 2

Error on ModelState.Activate()

PolemEngineering
Advocate
Advocate

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

0 Likes
185 Views
1 Reply
Reply (1)
Message 2 of 2

PolemEngineering
Advocate
Advocate

Getting the FactoryDocument works, because after assigning that document to a variable, that variable.IsModelStateFactory Is True.

If everything is already checked out , or with 'Select File From Vault' Open (CheckOut All), the code works without any problems. The problem occurs when the ReadOnly document is made writable by a CheckOut.

It looks like a timing thing... When I add Logger.Trace() lines in order to find the issue, then the problem moves.

I do a CheckWritability on the Document, but could it be that the ModelState member documents are not yet (fully) available at that given time?

Can this also be intercepted by a Check? I can hardly put everything in a Try-Catch statement.
An alternative is to no longer use the OnOpenDocument(After) event as one of the events for my ModelState-based Rules.

 

René van der Starre

0 Likes