mario52 wrote: ↑Fri Oct 16, 2020 1:10 pm
hi
with getSelectionEx() and SubElementNames[0 to xxx]
Code: Select all
try:
SubElement = FreeCADGui.Selection.getSelectionEx() # sub element name with getSelectionEx()
element_ = SubElement[0].SubElementNames[0] # name of 1 element selected
App.Console.PrintMessage("elementSelec : "+str(element_)+"\n\n")
except:
App.Console.PrintMessage("Oups"+"\n\n")
Code_snippets
mario
Thanks for your help, but this code can not deal my problem:
Follow your code, when program runs just when user clicked on the model (such as a cube model named Box) ,and pressed the CTRL key with the left mouse clicked on one Face (such as a face of Box named Face2 be clicked) the method "getSelectionEx" will worked, and can return the object (Face2 object), and the "SubElementNames" can contain the name "Face2" that the name of clicked face of the Cube model.
So which subobject can be returned , just depends on the user's mouse click.
But now my needed is : Give a part object, without user's mouse click, by python script list or print all the part object subobject name.
For example: give a Cube object, It consists of 6 faces, named Face1,Face2,Face3....Face6, by "FreeCAD.ActiveDocument.getObject("Box").Shape.Faces" can got the 6 Face object of the Box, But I did not kown the way to get the 6 Face object name, so I can not print the names of the 6 faces. Need the code to got all of the 6 faces name. Thanks a lot.
Code: Select all
gg=FreeCAD.ActiveDocument.getObject("Box")
gg.Shape.Faces
[<Face object at 00000000271F2E30>, <Face object at 00000000271F2EB0>, <Face object at 00000000271F2F30>, <Face object at 00000000271F2FB0>, <Face object at 00000000271F3030>, <Face object at 00000000271F30B0>]