Problems getting components using the document manager

I’m having an issue with the GetComponents Method (ISwDMConfiguration2) - 2021 - SOLIDWORKS API Help GetComponents method.

It is always returning a null and I don’t know why. Any ideas why this is happening.

Some information:

  • My key is 2021
  • SW 2021

Hi @AmenJlili,

  1. Open the assembly in SW and see if components are not missing (Due to component being renamed or moved). If you can see all components, rebuild all configurations, save the assembly and give it a try.
  2. You might have to look into ISwDMDocument27::GetExternalFeatureReferences3 method. Here is the example: Get the Current Name of the Configuration of a Suppressed Component (C#) - 2021 - SOLIDWORKS API Help

Regards,
Nilesh Patel

1 Like

Thanks for the response @nilesh. I understand what you are saying. I’m not trying to get the API call to work but rather understand why it is not working. Opening the document in SW kinda defeats the point really. I can’t even find an API call that tells if I need to open the document in SW and rebuild or not.

IsDirty() is returning false.

Sorry, I probably wasn’t clear. What I meant was to open the assembly manually in SW that you are having issue with to make sure there is no broken reference or all components suppressed.

I created a demo addin couple of years ago where I used GetComponents method and just tested it in SW2021 and seems to be working fine.

Are you having trouble with all assemblies or any particular assembly?

2 Likes

Hi Amen,

GetComponents is working fine in 2021 here.

Just a longshot:
Are you sure the file isn’t locked by any other process? (or your previous tryouts)

Eddy

1 Like

The file lock state shouldn’t matter.

Are you sure. Obviously you have more experience than I, but the “file in use by another process” has probably been my most common issue when dealing with reading files. In this case that error is buried in the API which catches it and just returns null with no informative reason why.

Possibly not related but interesting is how explorer.exe cannot display file details of Solid Edge file if that file is open in Edge.exe. When Solid Edge brought out BiDM (PDM without SQL or file archives) they exposed a bunch of metadata, which were then available as columns that can be added to explorer once SE is installed. Again, if the file is open in SE those properties will not show in explorer and I found that API could not >READ< properties from a file that was open in SE. I’ve learned and forgotten over and over that opening a file for read only operations may very well likely fail if that file is open for edits in another process.

Edt: I wish I knew how NotePad++ can open files that are open for edit by other process. It will even notify when the file on disk has been changed and offer to refresh. To me that is such a polished product to behave that way.

2 Likes

Thanks for the insight. I will keep all processes during my test and inform you guys!

I’m hesitant to remind you to read the remarks section of the help page you linked, it can be taken the wrong way and you could legitimately reply with an image of Captain Obvious. I wouldn’t do it but I’ve lost hours trying to solve something that was warned about in the Remarks section of SW API Help.

This method only returns data for documents created using SOLIDWORKS 2003 (Version 2200) and later. To get the version of a document, use ISwDMDocument::GetVersion.

1 Like

@bnemec : I really appreciate your reply! I’m already using GetVersion. I actually created the models using SW 2021.

1 Like

:+1:
Are there other configurations in the assembly file? Are you calling from active config or getting a config by name or some other way?

Have you tried other files always get the same?

Only one configuration. Default. Will have more details soon!

1 Like

I guess I’m not a very good rubber duck…

2 Likes

@AmenJlili, Could you share your assembly, if possible?

1 Like