You need to first run my LISP to delete all objects which are not in any viewport. Then you should seperate each layout as drawing.
Say I have 2 layouts with 2 viewports on it.
1. Run your LISP, it delete objects not on any view port
2. Run separate layout LISP, it creates 2 drawings with one view port on it. So Drawing 1 still remains objects on viewport 2 and drawing 1 remains objects on viewpor t1. These objects are not on any wiewport and I need to delete.
If I run this LISP 2 times, it will not delete all objects in Model Space but delete all those objects which are not included in any viewport. If you have already exported your viewports as seperate layouts and no viewports exist, then probably, all objects in Model Space would be deleted.
I have checked again and the LISP also delete all objects in Model Space ( I don't exported my viewports as seperate layouts). I tested on Autocad 2013 and Autocad 2015. Maybe because of my CAD version.
Thank you very much.