When objects are not in the view layer, just return false rather than throwing an error. As far as the script is concerned the object is not visible or selected when it's not in the current view layer.
When objects are not in the view layer, just return false rather than throwing an error. As far as the script is concerned the object is not visible or selected when it's not in the current view layer.