IFeature.Select2 Vs Ifeature.Select

Trying to mimic what @artem has done here I have a c# code that reads assembly components then activates them in their referenced configuration and then selects the flat-pattern of each body in that part. I am doing this on Solidworks 2020 and I have referenced Solidworks interop libraries 2018. For some reason IFeature.Select(false) works but IFeature.Select2(false,-1) does not work. And the interesting thing is that I didn’t have this problem when I was referencing Solidworks interop libraries version 2020!
One thing I noticed was that when I activate a specific configuration in the part, sometimes the graphical representation does not update to reflect that config, but IConfigurationManager.Activeconfiguration.Name returns the correct configuration name.

Can you post some of your code with an example so we can replicate this issue?

Check if your embed interop types = false for your SOLIDWORKS dlls.

Thanks @AmenJlili

public void SaveDxf(this AssemblyDoc assembly,string fullDxfFileName)
            if (!(assembly is ModelDoc2 cadModel))

            //I am using another extension method to get components
            IList<Component2> componets = assembly.GetComponentsByType(swDocumentTypes_e.swDocPART, topLevelOnly: false);

            foreach (Component2 componet in componets)
                var compModel = componet.GetModelDoc2() as ModelDoc2;
                compModel.Visible = true;

                //check cast-able?
                if (!(compModel is PartDoc part))

                var bodiesObjects = (object[])part.GetBodies2(((int)swBodyType_e.swSolidBody), BVisibleOnly: true);

                foreach (Body2 body in bodiesObjects)
                    //another extension method
                    var flatPattern = body.GetFlatPattern();

                    //go to next body if null
                    if (flatPattern == null)

                    if (!flatPattern.Select2(false, -1))
                        if (!flatPattern.Select(false))
                            throw new Exception("couldn't select the flat pattern");

                    var successfull= part.ExportToDWG2(fullDxfFileName, cadModel.GetPathName(),1, false, null, false, false,1,null);
                    if (!successfull)
                        throw new Exception("Couldn't export flat pattern");

I feel like the flag specified should be 0 if you want to select all items regardless of mark.

From the remark section of another function’s help page to set a mark property:
“Mark values (whether set by the SolidWorks application or by your application) must be powers of two (for example, 1, 2, 4, 8)”

no this didn’t work unfortunately

This reply doesn’t show :

  • Where you are showing the configuration.
  • Attached model to try your code.

If I were, I’d create Minimal Viable Example and git it to Github and paste it here.

1 Like

I was calling all the logic using the OnClose methode OnClose Method (IPropertyManagerPage2Handler9) - 2020 - SOLIDWORKS API Help
And this method blocks most commands as mentioned in the API help. I used the AfterClose event and that solved the problem.

Swwwwwwwwwwwwwwwwet. It’s always an X Y problem.