A third party developer once wanted to to find out how to turn off dimensions visible in a 3D view, using the Revit API. Controlling visibility of elements in a Revit model using the API is pretty straight-forward. The API exposes a SetVisibility() method on a View object which can be used to control the visibility of all elements of a given category – like dimensions in this case. The following minimal code snippet illustrates this approach –
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.HelloRevit.CS
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
Document doc =
commandData.Application.ActiveUIDocument.Document;
Categories categories = doc.Settings.Categories;
// get category for Dimensions
Category dim = categories.get_Item(
BuiltInCategory.OST_Dimensions);
using (Transaction trans = new Transaction(doc, "Visibility"))
{
trans.Start();
// toggle visibility
doc.ActiveView.setVisibility(dim, false);
trans.Commit();
}
return Result.Succeeded;
}
}
}

Leave a Reply