Get doc active configuration no matter what is loaded

I want to retrieve the active configuration of a model document given by its target file path.
And I want to always retrieve the value that is saved in the file, no matter what files are currently open/loaded.

How do I do that WITHOUT closing/reopening files before retrieving?

I tried using

  • ISldWorks.GetActiveConfigurationName(filePath),
  • first loading the IModelDoc (using IDocumentSpecification with target file path and then ISldWorks.OpenDoc7), then calling IModelDoc.ConfigurationManager.ActiveConfiguration.Name,

but both have the same problem:
If, prior to these calls, an assembly was loaded that contained the target file as a component, the calls will return the active configuration of that component, not the active configuration of the target file document.

To reproduce,

  • unpack the attached two files (assy2.sldasm and assy3.sldasm) and the macro (getActiveConfOfAssy3.swp) to some folder.
  • edit the macro and replace the current value of filePath variable by the correct one on your computer.
  • run the macro with no open document: then the found active configuration will be Sechseck10_confName.
  • run the macro with only assy2.sldasm open: then the found active configuration will be Sechseck30_confName.

To read the file on disk you can use the Document Manager API to get a swDMdocument, get its ConfigurationManager, and use GetActiveConfigurationName.