selection.first returns first object added to selection or model?
I use SU2017 and in this case selection.first returns the first object added to model.
is there any methods to obtain the first objecject added to selection?
thank you in advance
selection.first returns first object added to selection or model?
I use SU2017 and in this case selection.first returns the first object added to model.
is there any methods to obtain the first objecject added to selection?
thank you in advance
I guess you will not able to get it. The order of the entities inside the selection is determined by “unknown random rules”. Therefore the first item (like selection.firs
t or same selection[0]
) in this array is also “random”.
Check this:
Maybe use a SelectionObserver to track the order objects are selected?
But I don’t know how reliable this can be, you should treat the results very carefully and validate them with other ways if possible.
While a selection observer can be used to detect the selection order, the SketchUp selection is unordered by nature and an extension that relies on the selection order would feel alien to SketchUp. It can be done, but it may be a better idea to implement a tool that lets you pick one entity at a time and in between progresses to a new tool state with a new status text describing the current step.
def methods_to_obtain_the_first_objecject_added_to_selection( selection )
if selection.single_object?
return selection.first
else
UI.messagebox "Please select exactly one object!"
selection.clear
Sketchup.send_action "selectSelectionTool:"
end
end
def your_method
#bla bla
#.
model = Sketchup.active_model
selection = model.selection
first_object_selected = methods_to_obtain_the_first_objecject_added_to_selection( selection )
#.
#bla bla
end
your_method