Message 1 of 2
Using FactoryDocument of ActivatedObject throws an error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I am managing an external tool for Inventor 2022/2023 and we've had issues with the introduction of model states. The case we are trying to give support to is as follows:
- User activates a component (right click -> edit)
- User opens our external UI in order to set iProperties
- User can select if they want the iProperties to be set on all model states or only for the active state
- Based on the user's selection, we take the activated object -> get its FactoryDocument -> get FactoryDocuments model states-object -> set EditScope to kEditActiveMember or kEditAllMembers
- Set iProperties
- Set the previous EditScope back to what it was when process started
Here's a small example of the how we are currently going about with this up to point 4.:
Private Sub DemoEffect(sOption As String)
Dim oDoc As Document = API_App.ActiveDocument.ActivatedObject
Dim factoryDoc As Document = Doc_Get_FactoryDocument(oDoc)
Dim modelStates As ModelStates = Doc_Get_ModelState(factoryDoc)
If (sOption.Equals("ALL", StringComparison.InvariantCultureIgnoreCase)) Then
modelStates.MemberEditScope = MemberEditScopeEnum.kEditAllMembers
ElseIf (sOption.Equals("ACTIVE", StringComparison.InvariantCultureIgnoreCase)) Then
modelStates.MemberEditScope = MemberEditScopeEnum.kEditActiveMember
End If
End Sub
Public Function Doc_Get_FactoryDocument(doc As Document) As Document
If (doc Is Nothing) Then Return Nothing
Dim documentType As DocumentTypeEnum = doc.DocumentType
If (Not (documentType = DocumentTypeEnum.kPartDocumentObject Or
documentType = DocumentTypeEnum.kAssemblyDocumentObject)) Then
Return doc
End If
If (documentType = DocumentTypeEnum.kPartDocumentObject) Then
Dim def As PartComponentDefinition = doc.ComponentDefinition
If (def.IsModelStateMember) Then
Return def.FactoryDocument
End If
End If
If (documentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
Dim def As AssemblyComponentDefinition = doc.ComponentDefinition
If (def.IsModelStateMember) Then
Return def.FactoryDocument
End If
End If
Return doc
End Function
Public Function Doc_Get_ModelState(oDoc As Document) As ModelStates
If mdocCompOcc IsNot Nothing Then
Dim oDocum As Document = Doc_Get_FactoryDocument(mdocCompOcc.Definition.Document)
Return oDocum.ComponentDefinition.ModelStates
ElseIf Doc_Is_Assembly(oDoc) Then
Dim oAsmDoc As AssemblyDocument = oDoc
Dim oAsmCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Return oAsmCompDef.ModelStates
ElseIf Doc_Is_Part(oDoc) Then
Dim oPrtDoc As PartDocument = oDoc
Dim oPrtCompDef As PartComponentDefinition = oDoc.ComponentDefinition
Return oPrtCompDef.ModelStates
Else
Return Nothing
End If
Return Nothing
End Function
This process works perfectly for models, that have been opened to a window and for components, that are selected from model tree. However, the case where user activates the component, requesting the FactoryDocument throws an error "Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))" , which means we can't change the EditScope (it can't be changed from ModelStateMember).
Is Inventor supposed to support this use case? And is there a way around this issue?