Transferring view templates, not in 2014

Here is a follow up to my recent post about using the new 2014 API to copy a view template from one project to another.

Q. What if you aren’t using Revit 2014 and therefore can’t use the API to copy between documents?

A. Use this macro to select the template then do the following steps by hand:

  1. Copy the selected element to the clipboard
  2. Switch to the target document
  3. Paste Aligned to Current View
public void SelectTemplateOfActiveView()
{
    Document doc = this.ActiveUIDocument.Document;
    UIDocument uidoc = this.ActiveUIDocument;

    // Get the view template assigned to the active view
    ElementId id = doc.ActiveView.ViewTemplateId;
    if (id == ElementId.InvalidElementId)
    {
        TaskDialog.Show("Error","Active view does not have a view template.");
        return;
    }
    Element viewTemplate = doc.GetElement(id);

    // create a new empty SelElementSet
    SelElementSet selSet = SelElementSet.Create();

    // add the view template to the SelElementSet
    selSet.Add(viewTemplate);

    // make this SelElementSet selected in the Revit UI
    uidoc.Selection.Elements = selSet;
}

Leave a comment