Select only/all faces of object?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
danielfalck
Posts: 395
Joined: Fri Oct 07, 2011 8:58 pm
Location: Beaverton,Oregon, USA
Contact:

Re: Select only/all faces of object?

Post by danielfalck »

This might not be what you are looking for, but to parse the object and make a list of just the faces on it, try this:

Code: Select all

from FreeCADGui import Selection

obj=Selection.getSelection()[0].Shape
faces = []
for f in obj.Faces:
    faces.append(f)
andre
Posts: 96
Joined: Wed Nov 13, 2013 5:34 am

Re: Select only/all faces of object?

Post by andre »

Here where I get stumped:

selface = FreeCADGui.Selection.getSelectionEx()
for i in selface: #reselect items / faces again
FreeCADGui.Selection.removeSelection(App.ActiveDocument.getObject(i.ObjectName)) <-- works fine to select an entire object
FreeCADGui.Selection.addSelection(App.ActiveDocument.getObject(i.SubElementNames[0])) <-- returns error when trying to select just a face

Error received: <type 'exceptions.TypeError'>: argument 1 must be App.DocumentObject, not None
wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Select only/all faces of object?

Post by wmayer »

To add a single element to the selection:

Code: Select all

Gui.Selection.addSelection(App.ActiveDocument.Box,"Face1")
To get a list of selected sub-elements of an object:

Code: Select all

s=Gui.Selection.getSelectionEx()[0]
s.SubObjects
User avatar
Roland
Posts: 333
Joined: Fri Aug 21, 2015 2:20 pm

Re: Select only/all faces of object?

Post by Roland »

Dear Forum,

Has this issue ever been elaborated?
I have the same problem: A very complicated object with lots of internal faces that I want to get rid of, resulting in a FreeCAD model with the outside visible faces only.

My own progress sofar:
With Draft->Downgrade, I turned all solids of the model into faces. They are now with 10,000s.
To remove the internal ones by View->ClippingPlane, Select and Delete is no practicable solution, given the magnitude of faces.
An option could be to manually select the visible faces and copy them into a new document.

However, I did not find a FreeCAD tool to select visible faces only. E.g. Edit->Box Selection selects every face behind the selection window, including the invisible ones.

How to tackle this challenge?

Best regards,

Roland
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Select only/all faces of object?

Post by TheMarkster »

If you can create an object that contains the centers of mass of the desired faces within its BoundBox this macro will select those faces.

Usage: select the object to serve as the bounding box. Cubes work best because the boundbox is the same as the cube. You should make the cube invisible so you can see better which faces the macro has selected. Run the macro.

In this image I have a cube inside a cut object made from cutting one prism from another. The cut is partially transparent to better show the position of the cube.
Snip macro screenshot-1eaa89.png
Snip macro screenshot-1eaa89.png (87.47 KiB) Viewed 1824 times
In this image I made the cube invisible and ran the macro.
Snip macro screenshot-86489a.png
Snip macro screenshot-86489a.png (83.7 KiB) Viewed 1824 times
Attachments
boxed_faces_example.FCStd
(13.6 KiB) Downloaded 39 times
boxed_faces.FCMacro
(578 Bytes) Downloaded 50 times
User avatar
Roland
Posts: 333
Joined: Fri Aug 21, 2015 2:20 pm

Re: Select only/all faces of object?

Post by Roland »

Dear Markster,

I tested your example. Does the job as explained. Nice work!

Next step for me: to make it work on my model. Shall report.

Thanks a lot!

Roland
User avatar
Roland
Posts: 333
Joined: Fri Aug 21, 2015 2:20 pm

Re: Select only/all faces of object?

Post by Roland »

OK, Markster,

It is a temporary answer to my question. With your macro (Thanks!) I can select de internal faces of certain object types (not of all, see below).

My goal is to be able to end up with the external faces only. So, with your macro, I can select internal faces. Subsequently I can delete them. Note that Delete does remove everything belonging to the selected face. If that is a solid, the entire solid is deleted, including its external faces (which are to be kept). That implies that indeed (as I did already) I need to Downgrade all solids into faces, in order to keep the external faces.

This approach using your macro is not suitable for cylindrical objects, as the centre of mass of the surrounding external face is also inside the bounding box used for selection.

Best regards,

Roland
mario52
Veteran
Posts: 4701
Joined: Wed May 16, 2012 2:13 pm

Re: Select only/all faces of object?

Post by mario52 »

Hi

other idea : Select all faces in active view

or here Macro Select Hovering Image (select face or point or edge without click mouse) after use Part_ElementCopy Image for create the faces

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
Roland
Posts: 333
Joined: Fri Aug 21, 2015 2:20 pm

Re: Select only/all faces of object?

Post by Roland »

Dear Mario,

Thanks for your suggestions. I tried the Select Hovering. The principle works. However, it turned out to be too much manual labour.

It appeared that preparing hollow parts and recombining them by A2+ WB was a lot less laborious.
(still several hours, so it might be worthwhile to prepare a tool or macro, if it is a more general need)

Best regards,

Roland
mario52
Veteran
Posts: 4701
Joined: Wed May 16, 2012 2:13 pm

Re: Select only/all faces of object?

Post by mario52 »

Hi

tray Selecting adjacent surfaces (only the faces adjacent of the selected object is considered and one shell with the faces is created)

if you have one error in line 1 , replace the line by :

Code: Select all

shape = FreeCADGui.Selection.getSelection()[0].Shape
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Post Reply