How to set a custom parameter with AREA_TYPE?

How to set a custom parameter with AREA_TYPE?

b_hilaire
Participant Participant
254 Views
6 Replies
Message 1 of 7

How to set a custom parameter with AREA_TYPE?

b_hilaire
Participant
Participant

Hello to all,

 

I would like to initialize some custom parameters on HVAC zones with default values given in an Excel file. All parameters have already been defined into the project. Some of the are String, but some other are defined as AREA_TYPE as shown below:

 

b_hilaire_0-1748338173523.png

 

So I first get my default value from the Excel file -> myDefaultValue

 

Then I get my custom parameter to set the default value:

 

 foreach (Element e in zonesCollector)
{

  Parameter myCustomParameter = e.LookupParameter(myCustomParameterName);

  double d = double.Parse(myDefaultValue);

  myCustomParameter .Set(d);

}

 

The value is changed, but whith an understanging value...

 

What I am doing wrong?

 

Thank you in advance

 

Best regards

 

Bruno

0 Likes
Accepted solutions (1)
255 Views
6 Replies
Replies (6)
Message 2 of 7

TripleM-Dev.net
Advisor
Advisor

What do you mean exactly with "understanging value" , the units?

 

What kind of unit is the double that you set, an Area of just some number/decimal.

If it's a actual Area value you first need to set it to the internal units of revit (https://revapidocs.com/2024.htm?id=b5e8d065-d274-62f8-7b5d-89722f7c44f3.htm )

 

- Michel

 

 

0 Likes
Message 3 of 7

b_hilaire
Participant
Participant

Hello Michel,

 

The area unit in the Revit file is the m². So, I supposed that if  wanted to put my default value as a double, the area unit would be keeped with any conversion.

After some additional testing, I observed that I can give the default double value as a string using the method parameter.SetValueString.

 

It is a good way to do ?

Best regards

Bruno

0 Likes
Message 4 of 7

TripleM-Dev.net
Advisor
Advisor

You could do that, but wouldn't advise using a string an let it be converted by the API. There can be different rounding error with Double > String > Double convertion.

 

Take the double value of the Excel, and if those are in m2, convert it with the API builtin function (with the correct input unit argument) to the internal units double value and set that.

 

something like:

double areaInSquareMeters = 25.0; // your input value from the excel, so 25m2 in this case
double areaInInternalUnits = UnitUtils.ConvertToInternalUnits(areaInSquareMeters, UnitTypeId.SquareMeters);

// areaInInternalUnits = value to set in the parameter
//
// If the input isn't in m2, then change the UnitTypeId.SquareMeters to the correct type
0 Likes
Message 5 of 7

b_hilaire
Participant
Participant

Hello,

 

I tried the following code, but the result is still modified (I set 20 and I have 1.858):

 

NumberFormatInfo provider = new NumberFormatInfo();
provider.NumberDecimalSeparator = ",";
provider.NumberGroupSeparator = ".";
provider.NumberGroupSizes = new int[] { 3 };

double d = 20;
double areaInInternalUnits = UnitUtils.ConvertToInternalUnits(d, UnitTypeId.SquareMeters);
pp.Set(d);

 

Where I'am wrong?

Thanks in advance

Best regards

Bruno

0 Likes
Message 6 of 7

TripleM-Dev.net
Advisor
Advisor

pp.Set(d); should be pp.Set(areaInInternalUnits );

 

ps just convert directly: pp.Set(UnitUtils.ConvertToInternalUnits(d, UnitTypeId.SquareMeters));

 

The set value always needs to be in internal units

And the get will return internal units.

0 Likes
Message 7 of 7

b_hilaire
Participant
Participant
Accepted solution

Great, it works. Many thanks

0 Likes