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;
}
Advertisements

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 )

Google+ photo

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

Connecting to %s