Some users have tried to write their own code to generate the sql script, I suggest that you take a look at this article:
Script Views by Dependancy
http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=533
Additionally, it seems that Red Gate's SQL Compare and SQL Packager have addressed this issue. You may want to refer to this article for more information: