- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi There,
I have noticed something strange with revit dimensions in Revit 2014 and 2015.
I make a collection of dimensions and what I want to acchieve is to read if a prefix or suffix is used. When a value is found, put the value in a textbox.
The problem lies in the dim(seg).Prefix != null and dim(seg).Suffix != null part.
lets say a dimension has a suffix "mm". When asking for dim.Prefix it will return "" (empty string).
BUT, when no prefix or suffix is used, Revit will give a AccesViolation error and you closes revit without a warning!!
So, you can ask dim.Prefix or dim.Suffix when no pre- or suffixes are used. The value will not be an empty string, it just crashes revit.
The workaround I use now, is to check wheter the dim.value is a double. If not, I know a prefix or suffix is used. If the value can be parsed to a double, I bypass the dim.prefix call (which leads to crashing revit).
Does anybody know how to solve this in a proper way ?
foreach (Element el in elemset)
{
if (el.Category.Name.Equals("Dimensions"))
{
Dimension dim = el as Dimension;
if (dim.Segments.Size == 0)
{
if (string.IsNullOrEmpty(txtPrefix.Text) && dim.Prefix != null) txtPrefix.Text = dim.Prefix;
if (string.IsNullOrEmpty(txtSuffix.Text) && dim.Suffix != null) txtSuffix.Text = dim.Suffix;
}
else
{
foreach (DimensionSegment dimseg in dim.Segments)
{
if (string.IsNullOrEmpty(txtPrefix.Text) && dimseg.Prefix != null) txtPrefix.Text = dimseg.Prefix;
if (string.IsNullOrEmpty(txtSuffix.Text) && dimseg.Suffix != null) txtSuffix.Text = dimseg.Suffix;
}
}
}
}
Solved! Go to Solution.