The code works but as you can see in attached video, the nodes are not connected to Origin in order of creation. sometimes the oldest line of face is the first one which connects to Origin. What I want is to force my code to connect points to Origin from oldest to newest. is there any solution for this?
Thank you in advance for your help.
There is no way to determine selected edges in order of creation (unless you write complex code with complicated observers…) Neither the order of the selected entities. Moreover, the order of entities in the set is in no particular order and should not be assumed to be in the same order as the user selected the entities.
SketchUp has no inherent concept of “order of creation”. Because it shares vertices between edges and edges between faces, it feels free to rearrange and/or recreate them whenever that suits its immediate needs. Also, many of its collection classes use other data types than Arrays beneath the Ruby wrappers, which again does not assure retrieval in the same order as addition.
In your video, you appear to select by double-clicking on the face created by the edges. There is no way to assure what order this will put the edges into the selection. Even selecting just the edges one-by-one won’t assure any particular order in the selection.
As @dezmo noted, if you use the face’s outer loop vertices instead of the edges, you can at least be certain they will be in counter-clockwise order around the face’s normal, though you can’t be assured that the sequence will start with some particular vertex of interest to you.
You could achieve the desired effect if you wrote a custom line Tool that kept track of the points clicked in order, though that’s a lot more work than the simple snippet you posted.
Thank you @slbaumgartner, @dezmo
For the purpose that I have in mind, the custom line tool will be a quick and good solution as I always create my faces using line tool and no automatic process involved. I can create lines to origin right in time of using custom line tool to build the face.
Thanks again.