Name of a solid in a compound - from selection

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Name of a solid in a compound - from selection

Post by HoWil »

Good morning,

I need to improve the following script which allows for listing all elements below a cursor-click: https://forum.freecadweb.org/viewtopic. ... or#p151950

The goal is to click on e.g. a Face of a Fusion of two Solids and get all elements/objects below the click. I want to list the Faces below the cursor, the Fusion itself, and the two Solids, at least the one below the cursor.

I get the Faces and the Compound from element_list in the script below. The Solids inside the Compound can also be listed.

The only thing I miss is how can I identify these solids. How do I get their Label/Name to select them... in the case below the Label/Name of 's'.

Code: Select all

pos = (0, 0) # The compound in question has to be positioned at the lower left corner of the 3D-view-Window !!!!!!!!
element_list = FreeCADGui.ActiveDocument.ActiveView.getObjectsInfo((int(pos[0]), int(pos[1])))
e = element_list[0]

label_object = str(e["Object"]) # the label of e.g. the compound
label_component = str(e["Component"]) # the label of e.g. a face

compound = FreeCAD.ActiveDocument.getObject(label_object)
solids = compound.Shape.Solids
s = solids[0] # How do I identify this solid; how do I get its label???
I also included a min. .fcstd ... please use it as shown in the screenshot.
Element_selector_test_case_min.fcstd
(5.04 KiB) Downloaded 40 times
how to get a label/name of s ??
how to get a label/name of s ??
Screenshot from 2017-03-16 08-32-26.png (224.11 KiB) Viewed 2443 times
Thanks in advance,
HoWil
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Name of a solid in a compound - from selection

Post by HoWil »

Is there maybe also an easier way to to the requested.... find all solids, compounds,... a face/edge belongs to??
BR,
HoWil
mario52
Veteran
Posts: 4692
Joined: Wed May 16, 2012 2:13 pm

Re: Name of a solid in a compound - from selection

Post by mario52 »

hi

try this macro Macro_FCInfo

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.
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Name of a solid in a compound - from selection

Post by HoWil »

mario52 wrote:hi

try this macro Macro_FCInfo

mario
Dear Mario,
Thx for the info but it also only lists the name of the compound and not the solid of which the compound is made of:
FCInfo dialog and FC-Selection-view showing only 'BooleanFragments001' and 'Compound'.
FCInfo dialog and FC-Selection-view showing only 'BooleanFragments001' and 'Compound'.
Screenshot from 2017-03-16 14-23-39.png (255.26 KiB) Viewed 2410 times
In the dialogs of FEM-mesh-group and FEM-material-assignment one get the info
FEM-mesh-group dialog showing the needed information.
FEM-mesh-group dialog showing the needed information.
Screenshot from 2017-03-16 14-25-11.png (215.64 KiB) Viewed 2410 times
but I do not found the needed information in the code.

BR,
HoWil
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Name of a solid in a compound - from selection

Post by DeepSOIC »

Hi!
This problem is very much related to toponaming. OpenCascade does provide this information, and FreeCAD uses it to make face colors go through Boolean operations. However, none of that functionality is exposed to python so far.
mario52
Veteran
Posts: 4692
Joined: Wed May 16, 2012 2:13 pm

Re: Name of a solid in a compound - from selection

Post by mario52 »

hi
the text "BooleanFragment001" is long for the textedit try with the mouse in the text edit to see the complete name

the code for this is:

Code: Select all

sel = FreeCADGui.Selection.getSelection()
object_Name  = sel[0].Name 
App.Console.PrintMessage("object_Name    : "+str(object_Name)+"\n\n")

SubElement = FreeCADGui.Selection.getSelectionEx()
subElementName = Gui.Selection.getSelectionEx()[0].SubElementNames[0]
App.Console.PrintMessage("subElementName : "+str(subElementName)+"\n")

sel = FreeCADGui.Selection.getSelection()
object_Label = sel[0].Label
App.Console.PrintMessage("object_Label   : "+(object_Label)+"\n")
(see Code_snippets)

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.
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Name of a solid in a compound - from selection

Post by HoWil »

Dear mario,
It is more about the Solid3 in the BooleanFragments001 than the BF itself :!: The solids are newly named in a e.g. BooleanFragment and that name is needed.

Can you extract Solid3 from the selection in the given example :?:

Attached also the demo file incorporating the BooleanFragments of the Cylinder and the Cube:
Element_selector_test_case_bf.fcstd
(7.02 KiB) Downloaded 29 times
BR,
HoWil
mario52
Veteran
Posts: 4692
Joined: Wed May 16, 2012 2:13 pm

Re: Name of a solid in a compound - from selection

Post by mario52 »

hi
There is no object named Solid3
(i have unziped with "Project utility.."

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.
HoWil
Veteran
Posts: 1279
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Re: Name of a solid in a compound - from selection

Post by HoWil »

Let me explain it from an other view.

In the attached .fcstd above, there were tow solids 'merged' in a BooleanFragments-operation. This operation yields three! separate Solids since the intersecting domain is seen as new solid. This three solids can be found with the script-snippet from my first post see....
Three solids in the BooleanFragments object.
Three solids in the BooleanFragments object.
Screenshot from 2017-03-16 19-14-25.png (174.11 KiB) Viewed 2358 times
Here the original two solids were called:
Cylinder, Cube (see the Tree-View in the left part of the screenshot)
And the newly created three solids are listed without names in the Python console in the lower right part of the screenshot.

Now I would need the Labels of these three new solids.

Hope this helps understanding what I need to achieve.

BR,
HoWil
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Name of a solid in a compound - from selection

Post by DeepSOIC »

From Boolean fragments, it is technically possible to look up the original, but it requires a bit of rewrite of the tool. BooleanFramgents is just a feature around Part.Shape.generalFuse, which gives the source information along with the three solids. BooleanFragments simply discards that information. All other tools, such as connect, slice, and xor use that information to figure out, which fragments go to result and which are discarded.
Post Reply