I have the following assembly:
I am looking for a way to retrieve level3 via IModelDoc2.Extension.GetObjectByPersistReference3 from the IModelDoc2 of level2 while having level1 the active doc. It seems that this is not possible without loading some more data before making the GetObjectByPersistReference3 call. Even if the IComponent2 for level2 has IsLoaded() = true, it will only return null.
So the question is, what do I need to do in order to have level2's IModelDoc2 fully loaded, but WITHOUT the user noticing?
I tried 3 things:
1. load level2's IModelDoc2 via ISldWorks.OpenDoc6, silently and invisibly. This does not help.
2. load level2's IModelDoc2 via ISldWorks.OpenDoc7, silently and invisibly. This does not help either.
3. make level2's IModelDoc2 visible and then invisible again. This does help, but the user might notice, so I would prefer another way if possible. Also it is quite slow.
The attached macro contains all three methods: Just change the value of the "switch" variable before running it. The model level1.SLDASM must be the active doc for the macro to function.
And ideas what else could fully load the IModelDoc2 of level2?
I found a way!
Before loading the IModelDoc2 via ISldWorks.OpenDoc7 silently and invisibly, make the component lightweight:
' make component lightweight
level2Comp.SetSuppression2 (1)
' load component's model doc silently and invisibly
swApp.DocumentVisible False, 2
Dim docSpec As DocumentSpecification
Set docSpec = swApp.GetOpenDocSpec(level2Comp.GetPathName())
docSpec.ReadOnly = True
docSpec.Silent = True
Set level2Doc = swApp.OpenDoc7(docSpec)
swApp.DocumentVisible True, 2
I assume that OpenDoc7 internally checks the value of IsLoaded(), and if true, does nothing.
Setting the component to lightweight will set its IsLoaded() value to false, allowing to actually use OpenDoc7.