Code: Select all
v1 = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0]
v2 = FreeCADGui.Selection.getSelectionEx()[1].SubObjects[0]
v3 = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[1]
Code: Select all
v1 = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0]
v2 = FreeCADGui.Selection.getSelectionEx()[1].SubObjects[0]
v3 = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[1]
No, it returns objects only, not sub-objects. I have selected 4 vertices at the top of 2 objects, and I have only list of objects, ordered yes, but no way to get vertices, sub-selected-objects:
Code: Select all
>>> FreeCADGui.Selection.getCompleteSelection()
[<Part::PartFeature>, <Part::PartFeature>, <Part::PartFeature>, <Part::PartFeature>]
>>> FreeCADGui.Selection.getCompleteSelection()[0]
<Part::PartFeature>
>>> FreeCADGui.Selection.getCompleteSelection()[0].Name
'panelZY001'
>>> FreeCADGui.Selection.getCompleteSelection()[1].Name
'panelZY'
>>> FreeCADGui.Selection.getCompleteSelection()[2].Name
'panelZY'
>>> FreeCADGui.Selection.getCompleteSelection()[3].Name
'panelZY001'
>>>
Code: Select all
>>> FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0]
<Vertex object at 0x55a6464e5540>
OK sorry if so, maybe this is possible without observer?
This is a very strange function and I don't get what it is supposed to do. When selecting an object then it indeed returns an empty list. However, when you call Gui.Selection.enablePickedList() beforehand you get a result with getPickedList() but its behaviour is weird:How to use function FreeCAD.Selection.getPickedList() ? this returns empty array
This actually would be the right function. However, it's only useful in C++ but pretty useless in Python. In C++ you get a list of "SelObj" that keeps all relevant information, like object name, sub-element name, (x,y,z) click point, ...I explored 'getCompleteSelection()' and I find this function pretty useless as, in the case where you selected several items of the same object, it will just return several times the pointer to the object, but nothing that would allow to know the items that was selected. But maybe I missed something.
I saw there is something like enablePickedList() but I didn't know it should be called before selection so, it looks like this is some kind of observer embedded... there is also PickedPoints and this is almost what should be... but looks like the result refers only to first object? maybe there is some kind of switch to enablePickedList for all objects ?
Code: Select all
>>> FreeCADGui.Selection.enablePickedList()
>>> FreeCADGui.Selection.getPickedList()[0].PickedPoints
(Vector (18.0, 300.0, 618.0), Vector (18.0, 300.0, 618.0), Vector (18.0, 300.0, 618.0), Vector (18.0, 300.0, 617.7506103515625))
However, regarding this thing I made small progress, and if I select edge or face, the nearest vertex is selected. To do this I use observer and calculating distance. I have several problems with addSelection syntax but I guess finally get it to work and now the vertices selection will be pretty quick and easy, I hope so.