Issue with AsValueString()

Issue with AsValueString()

Anonymous
Not applicable
570 Views
4 Replies
Message 1 of 5

Issue with AsValueString()

Anonymous
Not applicable

Hello,

 

First of all, i'm working in meter.

As i could read on somes post, all data are store in feet in DB.

 

So my problème is that i have a value as '0.336 m³'

When i want to get it as : myparam.AsValueString(), i get '0.34 m³'

When i want to get it as myparam.AsDouble(), i get '11.84..' (the value as stored in database of revit)

 

The problem is that i don't find out to only get my value as shown : '0.336 m³'.

 

I read that i could use formatOptions, but i don't figure it out how to do..

 

I also read that use the method AsValueString() isn't advise, i cant' use builtinparameter for that.

 

 

Can you help me to get that ? 

 

Best regards,

0 Likes
571 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

I maybe found a solution.

 

I'm using FormatOptions like =

 

FormatOptions formatOtpions = new FormatOptions();

formatOption.UseDefault = false;

formatOptions.Accuracy = 0.0001

formatOption.DisplayUnits = myparam.DisplayUnitType

myparam.AsValueString(formatOption)

 

I'm gonna look if it works on all case and keep this update

 

 

UPDATE  :

 

If I use this, i have a lost of precision.

 

The result that i get is '0.3364'..

0 Likes
Message 3 of 5

jeremytammik
Autodesk
Autodesk

I suggest not using AsValueString at all:

 

https://thebuildingcoder.typepad.com/blog/2019/04/batch-processing-and-aspects-of-asstringvalue.html...

 

Good luck!

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 4 of 5

Anonymous
Not applicable

Hi Jeremy,

 

As i said, i would like to avoid using the AsValuestring methode.

But when i'm using the AsDouble for example, it's give me the value of my parametre, but as saved in revit, not as shown.. 

 

So i'm getting the converting value, but I have a leak of accuracy..

 

 

0 Likes
Message 5 of 5

jeremytammik
Autodesk
Autodesk

AsDouble is always at least as precise as AsValueString, and almost always more precise.

 

AsValueString generates an inaccuracy controlled by Revit, not you.

 

Using AsDouble, you have more accuracy and total control.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes