切记不要在事务中设置视图
public static void ActiveViewByName(UIApplication app, string viewname) { Document doc = app.ActiveUIDocument.Document; UIDocument uidoc = app.ActiveUIDocument; FilteredElementCollector collector = new FilteredElementCollector(doc) .OfClass(typeof(View)); foreach (View v in collector) { Debug.Assert(null != v, "never expected a null view to be returned" + " from filtered element collector"); // Skip view template here because view // templates are invisible in project // browser if (v.Name == viewname && !v.IsTemplate) { uidoc.ActiveView = v; } } }