Finding those constraining dimensions

Steve asks a lot of good questions and it is nice that the API is often able to help answer them. Recently he asked “Where are the Constraining Dimensions?

Here’s how to use the Dimension.IsLocked property to find those constraining dimensions:

Capture

For the entries where a segment of a multi-segment dimension is locked (such as #s 30, 31, 32), every reference of every segment is listed instead of just listing the two references related to the locked segment. This happens because while the Dimension class does has a References property, the DimensionSegement class has no such property. So the output is all references of the “parent” dimension instead of the two references of the relevant segment.

Capture

public void getConstraints()
{
    Document doc = this.ActiveUIDocument.Document;
    string data = "";
    int ctr = 1;
    foreach (Dimension d in new FilteredElementCollector(doc)
             .OfClass(typeof(Dimension))
             .Cast<Dimension>())
    {                
        if (d.NumberOfSegments == 0 && d.IsLocked)
        {
            data += ctr + ": id = " + d.Id.IntegerValue + " " + getReferenceNames(doc, d.References) + Environment.NewLine;
            ctr++;
        }
        else if (d.NumberOfSegments > 1)
        {
            foreach (DimensionSegment ds in d.Segments)
            {
                if (ds.IsLocked)
                {
                    data += ctr + ": id = " + d.Id.IntegerValue + " " + getReferenceNames(doc, d.References) + " - segment" + Environment.NewLine;
                    ctr++;
                }
            }
        }
    }
    if (data == "")
        data = "No locked dimensions";
    
    TaskDialog td = new TaskDialog("Locked Dimensions");
    td.MainContent = data;
    td.Show();
}

private string getReferenceNames(Document doc, ReferenceArray ra)
{
    string ret = "";
    foreach (Reference r in ra)
    {
        Element e = doc.GetElement(r);
        if (e.Category != null)
            ret += "(" + e.Category.Name + ") ";
        ret += e.Name + " & ";
    }
    
    // trim trailing " & "
    ret = ret.Remove(ret.Length - 3);
    
    return ret;
}
Advertisements

6 thoughts on “Finding those constraining dimensions

  1. Harry,
    this is awesome. I had no idea you could access this through API.
    Similarly,
    Is it possible to access if an element is Copy-monitored/monitored?

    Thanks
    JB

    • Thanks JB. The Element class has the following methods that you might find helpful.
      GetMonitoredLinkElementIds – Provides the link instance IDs when the element is monitoring.
      GetMonitoredLocalElementIds – Provides the local element IDs when the element is monitoring.
      IsMonitoringLinkElement – Indicate whether an element is monitoring any elements in any linked models.
      IsMonitoringLocalElement – Indicate whether an element is monitoring other local elements.

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