I cannot guarantee that what you are doing achieves what you want at all.
However, just looking at what you are doing with your code, here are a couple of suggestions:
You can use RevitLookup and other Revit database exploration tools to explore why this sometimes works and sometimes does not:
You can definitely make your code more concise, readable and effective in various ways.
Here is a suggestion for some improvement:
/// <summary>
/// Return all views with a
/// "View Template" parameter
/// </summary>
static IEnumerable<View> GetViewsWithTemplate(
Document doc )
{
BuiltInParameter bip_t
= BuiltInParameter.VIEW_TEMPLATE;
FilteredElementCollector views
= new FilteredElementCollector( doc )
.WhereElementIsNotElementType()
.OfClass( typeof( View ) );
IEnumerable<View> views_w_t = views
.Where( v
=> null != v.get_Parameter( bip_t ) )
.Cast<View>();
return views_w_t;
}
One possible reason for the differences may be that several different built-in parameters are used for the "View Template" property, e.g., BuiltInParameter.VIEW_TEMPLATE as well as BuiltInParameter.VIEW_TEMPLATE_FOR_SCHEDULE.
Maybe it is not sufficient to check only whether the parameter exists on the view, but also whether it has a valid non-zero value.
In any case, the parameter checking can be further speeded up by using a parameter filter to avoid the costly .NET or LINQ post-processing of results.
I hope this helps.
Cheers,
Jeremy