Open Component from Assembly

Is it possible to open a document from the current opened assembly one but not visible or minimized?

Snippet code:

sub Main()

(...)

dim open_doc as ModelDoc2

set open_doc = swApp.ActivateDoc3(...)

(...)

end usb

I’ve already tried the swApp.DocumentVisible = False method but the document is shown as default.

As the document is already loaded in the assembly the OpenDoc method will not work.

It would help to know what specifically you’d like to do. Some functionality only requires that you have a pointer to the model with the ModelDoc2 object.

For example, if you select traverse the feature tree components or select a component in the assembly, you can call IComponent2::GetModelDoc2 and then use that to do something like edit a custom property. There’s no need to open/activate it since it’s loaded in memory.

The macro do modifications in the sheetmetal’s flat pattern feature. Then it runs the commands:

(...)

set swFlatPattern = swFeat.GetDefinition

swFlatPattern.AccessSelections(...)

(...)

swFeat.ModifyDefinition(swFlatPattern, swModel, swComp)

(...)

The ModifyDefinition method “locks” the SolidWorks application after running the macro. You try to click anything but SW “freezes”. I’ve followed the remarks for this method as described bellow:

When you modify a feature in an assembly, this method leaves the assembly in Editing Part mode. You can switch back to editing the assembly by calling IAssemblyDoc::EditAssembly

The only way I succeed is opening the part document and perform all intended actions but it takes a longer execution time.

Have you tried using OpenDoc7 method?

OpenDoc7 (or OpenDoc6) only works for non loaded components. If there’s an assembly document opened then every assembly’s components are loaded.

Use DocumentVisible method with OpenDoc6.

This assumes the document you’re trying to open has not been loaded automatically by your assembly. If the document is already loaded in memory, use the iterator pattern from SldWorks.GetFirstDocument and then ModelDoc2::GetNext