All of the code you show is Python based, not Design Script. Design script can only be leveraged in Dynamo, and only via a code block. Python is more universal, runs in more platforms, and can call libraries and functions not initially loaded by Dynamo, but requires that all content is loaded as a result.
If you’d like to review how to do this with Design Script, start with the Dynamo Primer (all of it not just the design script section), then move onto the more in depth language manual and initial summary guide, and then review @solamour’s presentation material and examples on his GitHub. This will provide a good history, give you all the resources so you know what’s where, and follow the general sequence which most of us have gone through. Don’t struggle too much with the middle two as they are more technical in nature and serve more as reference guides for the end result.
Your other topic may have some new posts which are beneficial to review.
If you’d prefer to keep to Python, let us know so we can change the topic name. Python may in fact be better suited for your use in this case, but I’m not sure as I haven’t retyped or reviewed the code you provided. The error message is pretty telling though - adding a filter to remove view templates may be required. Other community members can certainly provide some guidance on that front. I also recommend looking into the work of people like @Thomas_Mahon, @Andreas_Dieckmann, @john_pierson and others who have open sourced Python in their packages, this forum, and elsewhere on the web.