Zooming a new view

If you are creating a new view and then want to use the UIView.Zoom method, you need to make the new view the active view and then refresh the view. If you don’t, the attempt to zoom will be futile.

public void createNewViewAndZoom()
{
    Document doc = this.ActiveUIDocument.Document;
    UIDocument uidoc = this.ActiveUIDocument;
    ViewFamilyType vft3d = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast<ViewFamilyType>().FirstOrDefault(q => q.ViewFamily == ViewFamily.ThreeDimensional);
    View view = null;
    using (Transaction t = new Transaction(doc, "make views"))
    {
        t.Start();
        view = View3D.CreateIsometric(doc, vft3d.Id);
        t.Commit();
    }
    zoom(uidoc, view);            
}

private void zoom(UIDocument uidoc, View view)
{
    // YOU NEED THESE TWO LINES OR THE ZOOM WILL NOT HAPPEN!
    uidoc.ActiveView = view;
    uidoc.RefreshActiveView();
    
    UIView uiview = uidoc.GetOpenUIViews().Cast<UIView>().FirstOrDefault(q => q.ViewId == view.Id);
    uiview.Zoom(5);
}

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();
    }
}

A bug in the new DimensionSegment.TextPosition property

UPDATE: This is fixed in Revit 2017

The Revit Sundial API enhancements, at least some of which are included in the current R2015 update, includes the new DimensionSegment.TextPosition property. Unfortunately, it incorrectly outputs the same position for all segments of a dimension. Autodesk is aware of the problem and hopefully it will be fixed soon.

unnamed

Document doc = this.ActiveUIDocument.Document;
UIDocument uidoc = this.ActiveUIDocument;
Dimension dim = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element)) as Dimension;
string d = "";
foreach (DimensionSegment dimseg in dim.Segments)
{
   d += dimseg.Value + Environment.NewLine + dimseg.TextPosition + Environment.NewLine + Environment.NewLine;
}
TaskDialog.Show("d",d);