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:

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.

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;
}
Like this:
Like Loading...