Understanding and using selections

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
drmacro
Veteran
Posts: 8866
Joined: Sun Mar 02, 2014 4:35 pm

Understanding and using selections

Post by drmacro »

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:
ClosedSketch.png
ClosedSketch.png (52.71 KiB) Viewed 893 times
The the selection object has 3 SubElementNames and 3 SubObjects.

With a sketch opened with the same objects selected:
SketchOpen.png
SketchOpen.png (52.35 KiB) Viewed 893 times
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."
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Understanding and using selections

Post by openBrain »

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. :lol:
drmacro
Veteran
Posts: 8866
Joined: Sun Mar 02, 2014 4:35 pm

Re: Understanding and using selections

Post by drmacro »

openBrain wrote: Tue Apr 20, 2021 3:56 pm Geometry is totally different when sketch closed or opened.
Indeed...
Precisely lines/curves adds their own vertices (start point, endpoint, center point for arcs/circles). This is why vertex numbering is different.
Has no one in the FC world heard of GUID's? :lol:
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).
Hmm...And that is precisely why I get frustrated with writing python in FC...

As you can see, the selected "things" have no common vertexes, so, no I expect 3 items in both cases:
Snip macro screenshot-d88786.png
Snip macro screenshot-d88786.png (17.75 KiB) Viewed 870 times
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. :lol:
Sure, I have figured out that geometry access in FC is horribly convoluted. :roll: :lol:
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
drmacro
Veteran
Posts: 8866
Joined: Sun Mar 02, 2014 4:35 pm

Re: Understanding and using selections

Post by drmacro »

openBrain wrote: Tue Apr 20, 2021 3:56 pm 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 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
SketchOpen3itm-selecton.png (3.86 KiB) Viewed 835 times
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Understanding and using selections

Post by openBrain »

drmacro wrote: Wed Apr 21, 2021 1:09 pm 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. :(
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 ?
drmacro
Veteran
Posts: 8866
Joined: Sun Mar 02, 2014 4:35 pm

Re: Understanding and using selections

Post by drmacro »

openBrain wrote: Wed Apr 21, 2021 1:37 pm ...
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 ?
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."
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Understanding and using selections

Post by openBrain »

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).
selSketch.png
selSketch.png (4.29 KiB) Viewed 757 times

Code: Select all

>>> Gui.Selection.getSelectionEx()[0].SubObjects[1].Point
Vector (-35.699589, -25.308640999999998, 0.0)
drmacro
Veteran
Posts: 8866
Joined: Sun Mar 02, 2014 4:35 pm

Re: Understanding and using selections

Post by drmacro »

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 ...
Ok, so maybe my confusion isn't so uncommon... :lol:
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Understanding and using selections

Post by openBrain »

drmacro wrote: Thu Apr 22, 2021 1:49 pm Ok, so maybe my confusion isn't so uncommon... :lol:
No it isn't. There is a former discussion from chrisb where the point already was that SubObjects is useless is sketch editing mode. :)
The problem is to know if it's a bug or a feature. :)
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Understanding and using selections

Post by openBrain »

Post Reply