AnsweredAssumed Answered

Face selection by name not working in Assembly

Question asked by Vincent Sciaccaluga on Sep 25, 2020
Latest reply on Sep 27, 2020 by Vincent Sciaccaluga



I have some difficulties to select a face by name inside an assembly.

The component selection works fine, I can see it in solidworks itself (green selection color) but when I do the loop on all faces, the currentFaceName variable is always empty "".


But in Solidworks when I right click on any face, "Face properties" the name is well displayed ! 


Does anyone know what's going on ? 



            string currentFaceName;

            SelectData swSelData = Document.SelectionManager.CreateSelectData();



            bool status1 = Document.Extension.SelectByID2(componentName, TemplateName.Component, 0, 0, 0, false, 0, null, 0);

            comp = Document.SelectionManager.GetSelectedObject6(1, -1);


            body = comp.GetBody();


            object[] tabFaces;

            tabFaces = body.GetFaces();


            for(int i=0; i<tabFaces.Length;i++)



                if (tabFaces[i] != null)


                    currentFaceName = Document.GetEntityName(tabFaces[i]);


                    if (currentFaceName == faceName)


                        Entity ent = (Entity)tabFaces[i];

                        bool status = ent.Select4(false, swSelData);


                        if (!status)


                            throw new Exception("!!! Fail to select face in assembly : " + faceName);