Selection order
-
Hi, I've been trying to apply an Attribute Dictionary to some entities in the outliner window but haven't been having my luck. It seems like Sketchup is picking a random entity as the place to start, rather than the first one I clicked on or selected like you would assume.
IE. My first entity gets assigned the dictionary 12 instead of 0, my second gets assigned the dictionary 13 instead of 1, etc.
I've double checked the code with others just to make sure it was correct, but I'm wondering if anyone else has experienced this randomized order of your selection.
-
I see the same. Evidently Sketchup does not promise to order the elements of the Selection based on the order in which you picked them on the GUI or Outliner. This may be a result of the data structure SketchUp uses to store the selection set (some structures optimized for search don't preserve order). You may need to give the entities names first so that you can test which one is which (this is a good idea anyway).
-
You cannot rely on the order of elements in a Selection.
If you freeze it usinges=selection.to_a
then the order is frozen - but not much use.
You can extract objects from a selection usinggrep
, e.g. ...
gs=selection.grep(Sketchup::Group)
Gives you an array of all groups in the selection.
You can make an array of their names [sorted] and then find their matching id - into an hash - which might then be in an order you want...
But you haven't really explained why the selected-items' order is so important for you...
Advertisement