What’s the code at line 81 of the script? The error message says that you’re giving it an Id that is not the id of a view.
Quick tip: since you’re repeating a lot of code to retrieve the elements and their ids, you can save the element Collector in a variable and use it to call both ToElements and ToElementIds.that way you only create one object instead of two, saving memory and cpu time
You can find a similar discussion on the autodesk forum, you have to compute the coordinates of the view range and select the elements using a spatial query