select solids of a Compound

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

select solids of a Compound

Post by bernd »

How is it possible to select a Solid of a Compound ?

I tried ...

Code: Select all

d = App.ActiveDocument

FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(d.Box)  # selects the whole Shape

FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(d.Box, 'Face1')  # selects Face1 of the Shape

FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(d.Box, 'Edge1')  # selects Edge1 of the Shape

FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(d.Box, 'Vertex1')  # selects Vertex1 of the Shape

FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(d.Box, '')  # selects the whole Shape

FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(d.Box, 'NotKnown')  # selects the whole solid

FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(d.Compound001)  # selects the whole Shape

FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(d.Compound001, 'Face1')  # selects Face1 of the Shape

FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(d.Compound001, 'Edge1')  # selects Edge1 of the Shape

FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(d.Compound001, 'Vertex1')  # selects Vertex1 of the Shape

FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(d.Compound001, '')  # selects the whole Shape

FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(d.Compound001, 'NotKnown')  # selects the whole Shape
it all returns something meaningful :)

but

Code: Select all

d = App.ActiveDocument
FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(d.Compound001, 'Solid1')  # selects the whole Shape
does not select the Solid but the whole Shape instead. I assume this is because the Solid is not a Subelement in FreeCAD. Is it somehow possible to select a Solid of a Compound?

Bernd


ref_solidselection.fcstd
(5.6 KiB) Downloaded 7 times
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: select solids of a Compound

Post by ulrich1a »

bernd wrote: Sun May 20, 2018 8:16 am Is it somehow possible to select a Solid of a Compound?
I think it will be difficult to get a Subsolid highlighted. But it is possible to select a Face and search in the faces from all solids of the selected object, which solid it covers.

I did this recently in a similar case, where I selected an edge and searched for the neighboring faces. See the attached macro. Select an edge and run the macro. It prints only in the console, as I use it for development purposes.

Ulrich
Attachments
details_ergruenden.py.zip
(1.22 KiB) Downloaded 7 times
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: select solids of a Compound

Post by bernd »

selection works already in FEM. I it similar. A solid selection modus has to be enabled and than a face or edge has to be selected, but I would like to highlight the solid. For this I use the addSelection method. This addSelection method works not on a solid of a compound. As a workaround to highlight (select) a solid of a compound I search in the compound for the faces of the solid and select all this faces, but than in selection window it does not write solid of compound is selected but lots of faces are selected. It looks pretty good but it is something like a hack.

The main question is, why is a solid not a sub element?
User avatar
yorik
Founder
Posts: 13659
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: select solids of a Compound

Post by yorik »

It is hard to know when a solid is selected (when all its faces are selected?), and it would also be hard to select a solid via the GUI anyway... Or we could introduce something like single click = select a face, double-click = select a solid, triple click = select the whole object? But I guess many people would scream in horror at such a change :D

To find the solid to which a face belongs is not hard, though:

Code: Select all

if myface.hashCode() in [face.hashCode() for face in s.Faces]: # myface is part of mysolid
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: select solids of a Compound

Post by bernd »

yorik wrote: Mon May 21, 2018 2:12 pm It is hard to know when a solid is selected (when all its faces are selected?), and it would also be hard to select a solid via the GUI anyway... Or we could introduce something like single click = select a face, double-click = select a solid, triple click = select the whole object? But I guess many people would scream in horror at such a change :D
selection with the mouse works already by selecting a sub element. I made a method for this. Ulrich did the same independent from me.

The problem is it is not possible to show the user the solid is selected. Means highlight the solid in main window with green color (for this I use the faces of the solid ATM), show in selection view the name of the solid etc. Thus the FreeCADGui addSelection method should support solids of Compounds.
User avatar
yorik
Founder
Posts: 13659
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: select solids of a Compound

Post by yorik »

the highlight system will only support points, edges or faces, so in any case at some point one would need to pass the individual faces and edges of a compound or solid to it... But indeed that could be done by the Selection module.
Post Reply