Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to retrieve the displayed value of a dimension?

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
983 Views, 8 Replies

How to retrieve the displayed value of a dimension?

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?

8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

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?

 

 

Message 3 of 9
Dale.Bartlett
in reply to: Anonymous

Any luck? Dale




______________
Yes, I'm Satoshi.
Message 4 of 9
michael-coffey
in reply to: Anonymous

Can you believe that 11 years later that this is still a problem?  I can...

Message 5 of 9

Glacial pace, sometimes known as 'Revit Time'




______________
Yes, I'm Satoshi.
Message 6 of 9
RPTHOMAS108
in reply to: Dale.Bartlett

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:

 

220508a.png

 

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.  

Message 7 of 9

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/

Message 8 of 9

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.

Message 9 of 9

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);
}

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community