Boost Your BIM – making Revit even better

February 18, 2013

What views use which view templates? (2012 edition)

Filed under: Views — harrymattison @ 10:26 am

Steve wrote at Revit OpEd:

When I travel back and forth between Revit versions, say between 12 and 13, I find myself missing things. For example I wanted to see (in 2012) how many views were assigned to view templates and which ones were really being used. In 2013 we can add that parameter to a View List, 2012 not so much. In 2013 we can select a view template and see how many views are assigned to it, in 2012…you get the idea. I wish life and project conditions didn’t make it hard to “just upgrade”. Just do it, as soon as you can!

Sometimes when you can’t upgrade your RVT to a newer version of Revit, you can use the Revit API to accomplish something similar (or even better!) than what you would do in the newer release of Revit. Here is a Revit 2012 macro that outputs a text file listing all view templates with the count and names of the views that use it as the default view template:

'Architectural Elevation' is Default View Template for 4 views

Elevation East, Elevation North, Elevation West, Elevation South,

'Architectural Plan' is Default View Template for 2 views

FloorPlan Level 1, FloorPlan Level 2,

'Architectural Reflected Ceiling Plan' is Default View Template for 2 views

CeilingPlan Level 1, CeilingPlan Level 2,

'Site Plan' is Default View Template for 1 views

FloorPlan Site,

'Structural Framing Plan' is Default View Template for 0 views

'Structural Framing Elevation' is Default View Template for 0 views

'Architectural Section' is Default View Template for 0 views

'Site Section' is Default View Template for 0 views

'Structural Section' is Default View Template for 0 views

'Architectural Presentation 3D' is Default View Template for 0 views

'Architectural Presentation Elevation' is Default View Template for 0 views

'Export to Civil Engineering' is Default View Template for 0 views
public void TemplateUse()
{
    Document doc = this.ActiveUIDocument.Document;
    Dictionary<string, IList<string>> dict = new Dictionary<string, IList<string>>();
    foreach (View viewTemplate in (from v in new FilteredElementCollector(doc).OfClass(typeof(View)).Cast<View>() where v.IsTemplate select v))
    {
        IList<string> viewsUsed = new List<string>();
        foreach (View view in (from v in new FilteredElementCollector(doc).OfClass(typeof(View)).Cast<View>() where !(v.IsTemplate) select v))
        {
            Parameter p = view.get_Parameter("Default View Template");
            if (p != null)
            {
                ElementId id = p.AsElementId();
                if (id != ElementId.InvalidElementId)
                {
                    Element e = doc.get_Element(p.AsElementId());
                    if (e.Name == viewTemplate.Name)
                        viewsUsed.Add(view.ViewType.ToString() + " " + view.Name);
                }
            }
        }
        dict.Add(viewTemplate.Name, viewsUsed);
    }

    // sort the dictionary based on the number of views in each list
    var items = from pair in dict orderby pair.Value.Count descending select pair;

    string filename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "ViewTemplateUsage.txt");

    using (StreamWriter sr = new StreamWriter(filename, false))
    {
        foreach (KeyValuePair<string, IList<string>> pair in items)
        {
            sr.WriteLine("'" + pair.Key + "' is Default View Template for " + pair.Value.Count + " views");
            string s = "";
            foreach (string name in pair.Value)
            {
                s += name + ", ";
            }
            sr.WriteLine(s);
            sr.WriteLine();
        }
    }
    Process.Start(filename);
}
About these ads

2 Comments »

  1. [...] to relieve the tension. It’s pretty cool how few lines of code and provide useful answers. Check out his post. Be sure to read his post tomorrow too, he’s going to enhance it a bit and share that [...]

    Pingback by View Template Usage | BIM i praksis — February 18, 2013 @ 5:58 pm

  2. [...] to relieve the tension. It’s pretty cool how few lines of code and provide useful answers. Check out his post. Be sure to read his post tomorrow too, he’s going to enhance it a bit and share that [...]

    Pingback by View Template Usage | Revit Architecture India — February 19, 2013 @ 1:44 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: WordPress Classic. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 391 other followers