Get View Range From Selection Box or Selected Elements

Have a look here?

You have to scroll down a little in that topic.