for a Dimension there is a ValueString property which is the length measured by that dimension. However the value showed on the screen or on the printed sheets, is often a rounded value of ValueString. It seeems that Dimension Class does not have any property for obtaining this value. Is there a way to get this value?
Adding to the topic:
- Dimension.ValueString returns the real value of a dimension
- What is the number that is returned by using Dimension.Value?!
For segmented Dimensions I used a DimensionSegmentArray and filled it with the segments of the dimension. Using DimensionSegment.ValueString for each segment returns the Value which is showed on the screen or the sheet and there is no way to access the real value, this time!!. The opposite approach for Dimension element. It shows an unconsistent approach towards Dimension and segmented dimension in RevitAPI.
Any solutions for these situations?
Can you believe that 11 years later that this is still a problem? I can...
Glacial pace, sometimes known as 'Revit Time'
So in summary it seems:
DimensionSegment.ValueString displays the value as is on screen including suffix etc.
DimensionSegment.Value reports the double value in feet of the dimension segment.
The error is with the Dimension class i.e.
Dimension.Value is ok but
Dimension.ValueString seemingly reports the value as taken from Value parameter of the Dimension object which is using the project units for length and not those set for dimension primary units:
To get the actual displayed value for non-segmented dimensions you can likely use the unit format options of the dimension (DimensionType.GetUnitsFormatOptions ) in conjunction with UnitFormatUtils.Format
I assume the issue is not affecting the DimensionSegment class because it isn't an Element in it's own right and so doesn't read from AsValueString of DIM_VALUE_LENGTH.
Ultimately there is also the possibility of alternative units being displayed below the dimension line, so dimension ValueString is not going to cover that aspect either.
I hate saying the w word (workaround) because that means Autodesk will never ever fix something if there is one. But you can take a look at this page and decide for yourself. https://www.sixtysecondrevit.com/2018-09-04-get-the-real-display-string-value-of-revit-dimensions/
I think an extension method could be created for this that doesn't require a transaction roll back.
I've not looked at what UnitFormatUtils.Format produces in terms of a string but I had assumed you could just feed the primary units format options etc. for the DimensionType of the Dimension into UnitFormatUtils.Format to get the value rather than having to change the project units.
I think you are right. I created this macro with no transaction and appears to work:
public void GetDimValueString()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
// Pick a dimension
Reference r = null;
string message = string.Empty;
try
{
r = uidoc.Selection.PickObject(ObjectType.Element, "Pick dimension" );
}
catch( Autodesk.Revit.Exceptions.OperationCanceledException )
{
return;
}
if( null == r )
{
message = "Null pick object reference.";
return;
}
Element e = doc.GetElement( r );
Dimension dim = e as Dimension;
//
var dimFormat = dim.DimensionType.GetUnitsFormatOptions();
var units = dim.Document.GetUnits();
FormatValueOptions options = new FormatValueOptions();
options.SetFormatOptions(dimFormat);
string valueString = UnitFormatUtils.Format(units, SpecTypeId.Length, (double) dim.Value, false, options);
TaskDialog.Show("Info", "Value string is: " + valueString);
}