Change the titleblock on a sheet

The titleblock is a FamilyInstance (just like a desk or door), so changing from one type to another is just a matter of finding the FamilyInstance (in this sample by looking in the active view for a FamilyInstance of the Titleblock category) and then changing its FamilySymbol.

public void changeTitleBlock()
{
    Document doc = this.ActiveUIDocument.Document;
    
    // find the titleblock in the active view
    FamilyInstance fi = new FilteredElementCollector(doc, doc.ActiveView.Id)
        .OfClass(typeof(FamilyInstance))
        .OfCategory(BuiltInCategory.OST_TitleBlocks)
        .FirstOrDefault() as FamilyInstance;
    
    // find the titleblock family symbol with the desired name
    FamilySymbol fs = new FilteredElementCollector(doc)
        .OfClass(typeof(FamilySymbol))
        .OfCategory(BuiltInCategory.OST_TitleBlocks)
        .FirstOrDefault(q => q.Name == "D 22 x 34 Horizontal") as FamilySymbol;           
    using (Transaction t = new Transaction(doc,"Change titleblock"))
    {
        t.Start();
        fi.Symbol = fs;
        t.Commit();
    }
}
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