Hello
I want to automatically create a set of face selectors (sometimes several hundred) according to certain criteria (area and altitude).
I have 2 solutions: either select all the faces, make a selection set and remove from the selection set the faces that do not match the criteria, or test all the faces and add those that are compliant in a selection set.
Can you guide me and possibly give me the syntax of the code please?
Kind regards
Frédéric
To select all the faces it is quite simple:
https://help.solidworks.com/2020/english/api/sldworksapi/select_all_faces_on_part_example_vb.htm?verRedirect=1
On the other hand, for the exclusion part, depending on the area and/or altitude, it will be much more difficult.
For the surface I found this (https://r1132100503382-eu1-3dswym.3dexperience.3ds.com/#community:yUw32GbYTEqKdgY7-jbZPg/post:RN7LsVLNRHKp5EW5viOLLw):
Dim Area As Double
Area = swFace.GetArea
Debug.Print "Area = " & Area & " m²"
Debug.Print "Area = " & Math.Round(Area * 1000000, 1) & " mm²"
On the other hand, the altitude of a surface, I don't know but we should rather start from points, I guess.
Edit: for the altitude try this:
https://www.codestack.net/solidworks-api/geometry/get-face-center-parameters/
Thank you very much for your answer. Yes, this is exactly the code needed for the selection of faces and to retrieve the coordinates.
For the moment I use:
Set swSelectionSet1 = swModelDocExt.SaveSelection(errors) to create a selection set
and
deselVal = swSelMgr.DeSelect2(selObjIndex, selectionMark) to deselect faces that do not meet the criteria.
I still have some problems with the vertical faces which are not always well recognized... and therefore not deselected!
Keep us informed of your progress, and post us your final code for the community.
Here is the functional version.
Thank you for your help!
select_faces.swpcarte_temp.sldprt
@fgauvreau thank you perfectly for the exchange and don't forget to close your topic by selecting the best answer.