Name of a solid in a compound - from selection

Need help, or want to share a macro? Post here!
HoWil
Posts: 373
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

Name of a solid in a compound - from selection

Postby HoWil » Thu Mar 16, 2017 7:36 am

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 5 times

Screenshot from 2017-03-16 08-32-26.png
how to get a label/name of s ??
Screenshot from 2017-03-16 08-32-26.png (224.11 KiB) Viewed 176 times

Thanks in advance,
HoWil
HoWil
Posts: 373
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

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

Postby HoWil » Thu Mar 16, 2017 7:37 am

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

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

Postby mario52 » Thu Mar 16, 2017 10:28 am

hi

try this macro Macro_FCInfo

mario
Windows 10
Maybe you need a special feature, go into Macros_recipes and Code_snippets. My macros on Gist.github
HoWil
Posts: 373
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

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

Postby HoWil » Thu Mar 16, 2017 1:37 pm

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:
Screenshot from 2017-03-16 14-23-39.png
FCInfo dialog and FC-Selection-view showing only 'BooleanFragments001' and 'Compound'.
Screenshot from 2017-03-16 14-23-39.png (255.26 KiB) Viewed 143 times


In the dialogs of FEM-mesh-group and FEM-material-assignment one get the info
Screenshot from 2017-03-16 14-25-11.png
FEM-mesh-group dialog showing the needed information.
Screenshot from 2017-03-16 14-25-11.png (215.64 KiB) Viewed 143 times

but I do not found the needed information in the code.

BR,
HoWil
DeepSOIC
Posts: 4462
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

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

Postby DeepSOIC » Thu Mar 16, 2017 1:48 pm

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
Posts: 1845
Joined: Wed May 16, 2012 2:13 pm

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

Postby mario52 » Thu Mar 16, 2017 3:22 pm

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
Windows 10
Maybe you need a special feature, go into Macros_recipes and Code_snippets. My macros on Gist.github
HoWil
Posts: 373
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

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

Postby HoWil » Thu Mar 16, 2017 4:49 pm

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 2 times

BR,
HoWil
mario52
Posts: 1845
Joined: Wed May 16, 2012 2:13 pm

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

Postby mario52 » Thu Mar 16, 2017 5:43 pm

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

mario
Windows 10
Maybe you need a special feature, go into Macros_recipes and Code_snippets. My macros on Gist.github
HoWil
Posts: 373
Joined: Sun Jun 14, 2015 7:31 pm
Location: Austria

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

Postby HoWil » Thu Mar 16, 2017 6:19 pm

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....
Screenshot from 2017-03-16 19-14-25.png
Three solids in the BooleanFragments object.
Screenshot from 2017-03-16 19-14-25.png (174.11 KiB) Viewed 92 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
DeepSOIC
Posts: 4462
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

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

Postby DeepSOIC » Thu Mar 16, 2017 7:04 pm

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.