Understanding and using selections
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Understanding and using selections
I'm trying to get my head around how to access things selected by the user.
With a sketch closed and a point, a vertex of a line, and a lined selected: The the selection object has 3 SubElementNames and 3 SubObjects.
With a sketch opened with the same objects selected: The the selection object has 3 SubElementNames, but 2 SubObjects.
And why is the name Edge4 the same in both cases, but the Vertex names different?
With a sketch closed and a point, a vertex of a line, and a lined selected: The the selection object has 3 SubElementNames and 3 SubObjects.
With a sketch opened with the same objects selected: The the selection object has 3 SubElementNames, but 2 SubObjects.
And why is the name Edge4 the same in both cases, but the Vertex names different?
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Re: Understanding and using selections
Geometry is totally different when sketch closed or opened.
Precisely lines/curves adds their own vertices (start point, endpoint, center point for arcs/circles). This is why vertex numbering is different.
With sketch opened, only 2 subobjects are selected probably because 1 of the vertices actually is an endpoint of the 'Edge4' line. So inside sketcher they are the same geometry (object).
We recently discussed how to find sketch geometry matching a selection, will find a link. => EDIT : OK, you were the OP of the thread I was thinking about. So probably you know what I'm talking about.
Precisely lines/curves adds their own vertices (start point, endpoint, center point for arcs/circles). This is why vertex numbering is different.
With sketch opened, only 2 subobjects are selected probably because 1 of the vertices actually is an endpoint of the 'Edge4' line. So inside sketcher they are the same geometry (object).
We recently discussed how to find sketch geometry matching a selection, will find a link. => EDIT : OK, you were the OP of the thread I was thinking about. So probably you know what I'm talking about.
Re: Understanding and using selections
Indeed...
Has no one in the FC world heard of GUID's?Precisely lines/curves adds their own vertices (start point, endpoint, center point for arcs/circles). This is why vertex numbering is different.
Hmm...And that is precisely why I get frustrated with writing python in FC...With sketch opened, only 2 subobjects are selected probably because 1 of the vertices actually is an endpoint of the 'Edge4' line. So inside sketcher they are the same geometry (object).
As you can see, the selected "things" have no common vertexes, so, no I expect 3 items in both cases:
Sure, I have figured out that geometry access in FC is horribly convoluted.We recently discussed how to find sketch geometry matching a selection, will find a link. => EDIT : OK, you were the OP of the thread I was thinking about. So probably you know what I'm talking about.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Re: Understanding and using selections
As shown in the previous image there are 3 separate items selected. SubElementNames returns 3 items. But, SubObjects returns 2.
But, in an attempt to confirm my sanity...which failed.
I created the following geometry and selection in an open sketch. As before SubElementNames returns 3 items. But, SubObjects returns 3.
I fail to find my sanity nor logic in this behavior.
- Attachments
-
- SketchOpen3itm-selecton.png (3.86 KiB) Viewed 835 times
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Re: Understanding and using selections
A guess is that maybe in your previous test you selected a vertex which was actually coincident between 2 lines. In this case the sketcher internally selects the constraint (and not the vertex) which may explain why. Could you test with such a setup ?
Re: Understanding and using selections
Hmm...it appears the objects returned by the SubObjects is the vertex (lower right, vertex of the rectangle) and the edge (left horizontal of the rectangle).
And the 3rd item of the SubElementNames list is the point object (upper left).
There is something about the way the geometry is created.
If the rectangle is created with the rectangle tool, then SubElementNames list is 3, and SubObjects is 2 (the selected edge and the vertex of the edge).
if the rectangle is created by drawing one edge at a time (i.e.with the line tool), then SubElementNames list is 3, and SubObjects is 3.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Re: Understanding and using selections
I even have something very weird. In sketch editing mode, if I do the below sketch & selection, the vertex appearing in SubObjects is none of the selected ones. It's an endpoint (probably the starting one I guess) of the selected edge. Both selected vertex are totally ignored (but they are correct in SubElementNames).
Code: Select all
>>> Gui.Selection.getSelectionEx()[0].SubObjects[1].Point
Vector (-35.699589, -25.308640999999998, 0.0)
Re: Understanding and using selections
Ok, so maybe my confusion isn't so uncommon...openBrain wrote: ↑Thu Apr 22, 2021 1:03 pm I even have something very weird. In sketch editing mode, if I do the below sketch & selection, the vertex appearing in SubObjects is none of the selected ones. It's an endpoint (probably the starting one I guess) of the selected edge. Both selected vertex are totally ignored (but they are correct in ...
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Re: Understanding and using selections
Looks like you already were in https://forum.freecadweb.org/viewtopic.php?f=22&t=53127