Get total length of multiple lines & units conversion

This post on the Revit Ideas forum inspired a new lecture on the Boost Your BIM Revit API course at Udemy. It is a great example of how just a few lines of code (17, to be exact) can be written in just a few minutes to do something useful.


Override Dimension Text (part 2)

Building on our last post, here is the finished tool with UI that allows you to modify the dimension text on a single or multi-segment dimension by selecting the dimension, not the dimension text.

FREE Installer:

add additional way to get to Dimension Text dialog (to edit Dimension’s text)

In the Revit Ideas forum it was asked if it can be possible to access this dialog to change dimension text without having to select the dimension’s text itself. Either the text has been overridden with an invisible, empty character, a view break was used, or for some other reason it isn’t simple to select the dimension’s text. Or you want to avoid the problem of moving the dimension text by mistake when you try to click it.

Fortunately, the API gives you access to most everything in this dialog (maybe not “show label in view” and “segment dimension leader visibility”). The code is below to handle a dimension with a single segment (code for the Dialog form is not included) and it could also be enhanced to work with a multi-segment dimension if the form listed the text of each dimension segment so you could specify which segment to modify.

Is there interest in a Udemy lecture showing how to code the form? Or posting it as an app in the Autodesk store?

public void dimText()
    Document doc = this.ActiveUIDocument.Document;
    UIDocument uidoc = this.ActiveUIDocument;
    Dimension dim = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element, "Select dimension")) as Dimension;
    if (dim.NumberOfSegments > 1)
        TaskDialog.Show("Error", "Can only run when the dimension has a single segment");
    string above = "";
    string below = "";
    string prefix = "";
    string suffix = "";
    string replaceWithText = "";
    using (FormDimText form = new FormDimText(dim))
        if (form.DialogResult == System.Windows.Forms.DialogResult.Cancel)
        above = form.getAbove();
        below = form.getBelow();
        prefix = form.getPrefix();
        suffix = form.getSuffix();
        replaceWithText = form.getReplace();
    using (Transaction t = new Transaction(doc, "Dim Text"))

        dim.Above = above;
        dim.Below = below;
        if (replaceWithText == null)
            dim.Prefix = prefix;
            dim.Suffix = suffix;    
            dim.ValueOverride = replaceWithText;