oDoc.ComponentDefinition.Occurrences empty in invisble doc?

oDoc.ComponentDefinition.Occurrences empty in invisble doc?

croQY976
Explorer Explorer
407 Views
2 Replies
Message 1 of 3

oDoc.ComponentDefinition.Occurrences empty in invisble doc?

croQY976
Explorer
Explorer

Hi

 

I have an Inventor assembly model, that is configurable with user parameters.

Whenever parameters are changed, an iLogic rule ("Rule0") is called, that will update the model according to the actual parameters. A main thing in Rule0 is to loop through all component occurrences and set the Suppressed state of each according to the actual parameters.

 

It goes like this:

Dim oDef As Inventor.ComponentDefinition
oDef = oDoc.ComponentDefinition
 
Dim componentName As String = GetComponentName()
Logger.Trace("componentName = " + componentName)
Logger.Trace("#Components: " & oDef.Occurrences.Count)
 
For Each oOcc As Inventor.ComponentOccurrence In oDef.Occurrences
    Component.IsActive(oOcc.Name) = (oOcc.Name = componentName)
Next


It works fine.

Now, I have some external code, that does the following using API calls:

* Opens the assembly file described above

* Loads parameters from an external XML file and applies it to the model

* Explicitly calls "Rule0" to update the model

* Saves the model with a new name ("doc.SaveAs")

 

This also works fine.

 

Now comes the issue: If I change the external code to open the model in "invisible mode", like this:

Dim model As Inventor.AssemblyDocument = ThisApplication.Documents.Open(pathToSourceModel, False)

 

...then the logic breaks. I have debugged it down to the issue, that in Rule0 of the model, oDef.Occurrences is empty. This has been confirmed by the logger trace

    Logger.Trace("#Components: " & oDef.Occurrences.Count)

...showing that there are no components. 

 

As a consequence, Rule0 does not update the model correctly.

Is this expected behavior, that no component occurrences are present, when the document is opened in invisible mode? Is there any explicit call, that can make them appear?

0 Likes
Accepted solutions (1)
408 Views
2 Replies
Replies (2)
Message 2 of 3

croQY976
Explorer
Explorer

OK, I think I have figured out now, what is causing the issue. In Rule0, ThisApplication.ActiveDocument is used to get the document, from which to retrieve the components. Seems like this works fine, when the doc is visible, but not when it is hidden. So the code tries to get components from the wrong document. I will investigate this further, I guess it should be possible in Rule0 to refer to the document itself, which contains the rule.

0 Likes
Message 3 of 3

croQY976
Explorer
Explorer
Accepted solution

This solved it: In Rule0, instead of referring to ThisApplication.ActiveDocument, I now use:

Function GetThisDoc() As Inventor.AssemblyDocument
    Dim oDoc As Autodesk.iLogic.Runtime.CadDoc = ThisDoc
    Dim oModelDoc As Inventor.AssemblyDocument = oDoc.ModelDocument
    Return oModelDoc
End Function

0 Likes