Turning off Dimensions using Revit API

By Saikat Bhattacharya

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;

    }

  }        

}


Comments

One response to “Turning off Dimensions using Revit API”

  1. setVisibility no longer works. Is there another way to do this?

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading