Get BarDiameter from a rebar

Hello,
I am sharing a script with which I have a couple of issues.
I assigned some numbers as a reference.

In case 1, since I am using a BuiltIn Parameter, it doesn’t work if i write:

using DB = Autodesk.Revit.DB;

but it works if I write

using Autodesk.Revit.DB;

Case 2 works fine but if I read the built-in parameter (which I don’t like)

Case 3 doesn’t work if I choose not to show “out”.

In case 5 I am getting the rebar diameter property of the RebarBarType.
I am trying to get it directly for the rebar, first the RebarBarType then the diameter, which is in case 4, but it doesn’t work.

Sorry for the long question and i hope someone will be able to help

Get rebar diameter.gh (11.3 KB)
Revit.rvt (6.7 MB)

Hi Drilon,

Is the question how to read the parameter of the Type using C#?

Hi Japhy,
The end goal is to create a C# component that gets as input the rebar and outputs the diameter (which is what case 2 is doing). What I don’t like in this is that I have to use :

myRebar.get_Parameter(BuiltInParameter.REBAR_BAR_DIAMETER)

and the output is not in the default units and I have to convert it manually.
What I want to do is to get RebarBarType of the input rebar and then for this, I can read BarDiameter.
Of course, if I can read Bar Diameter directly (without getting RebarBarType), it would be even better.

I need to use the first method shown in this post:

In order to get the Bar Diameter, you got to get the type first. BarModelDiameter method will give the result as a float. But the result still will be in Imperial units. I tried it in Python and still got the result in imperial.
https://apidocs.co/apps/revit/2022/206e9dc6-5fc1-c0a8-6c76-d5a53ee93a39.htm

Hi @drilonshabani,

In case 1, if you add an alias for the Autodesk.Revit.DB you need to use that alias to reference types on that namespace.

double elementParameter = myRebar.get_Parameter(DB.BuiltInParameter.REBAR_BAR_DIAMETER).AsDouble();

Case 4: BarDiameter is not a member of Autodesk.Revit.Structure.Rebar it is on Autodesk.Revit.Structure.RebarBarType.

Case 5: Same problem as case 1, you should use the full name from the alias.

DB.Structure.RebarBarType myRebarType = myRebar.Document.GetElement(myRebar.GetTypeId()) as DB.Structure.RebarBarType;

To convert to Rhino units you can do the following:

Diameter = UnitConverter.ConvertFromHostUnits(myRebarType.BarModelDiameter, RhinoDocument.ModelUnitSystem);

The oposite would be…

myRebarType.BarModelDiameter = UnitConverter.ConvertToHostUnits(Diameter, RhinoDocument.ModelUnitSystem);
1 Like

Thank you very much Kike.
It’s crazy that I wasn’t using UnitConverter.
I managed to get also RebarBarType from the Rebar element and then the Diameter from RebarBarType.

Hi @kike
Why can i no longer use UnitConverter?
Is there any other method now?

Hi @drilonshabani,

You have GeometryEncoder.ToInternalLength and GeometryDecoder.ToModelLength on the same class you are using to convert other kind of unit related values.

1 Like