Hi All, @c.poupin @Mike.Buttery
In the following extracted part of my code, where I use WPF forms, I need the value of the concrete compressive strength entered by the user to calculate the YoungModulus
for this material. For others purposes, I have already converted this value to Revit internal units (UnitTypeId.Megapascals
) using the following function:
def _input_to_MPA(value):
"""Convert the textual value for Compressive strength of concrete to MPA."""
return UnitUtils.ConvertToInternalUnits(float(value), UnitTypeId.Megapascals)
However, I am encountering difficulties in either reconverting this value back from internal units or determining a constant that allows me to compute the correct value for YoungModulus
in megapascals using the formula:
# the variable contrainte in my code refers to the Compressive strength of concrete
E = 11000 * contrainte ** (1 / 3)
and according to this line in the code:
asset.SetYoungModulus(UnitUtils.ConvertToInternalUnits(11000 * float(c) ** (1 / 3), UnitTypeId.Megapascals))
Here the part of the code wher I create the concrete material
class Create_Tank(Window):
def __init__(self):
....
....
def _collect_input_data(self):
"""Collect and convert input data from the UI"""
....
....
try:
self.data = {
"A": _input_to_meters(self.A_value.Text),
"B": _input_to_meters(self.B_value.Text),
"H": _input_to_meters(self.H_value.Text),
"ep": _input_to_meters(self.ep_value.Text),
"contrainte": _input_to_MPA(self.contrainte_value.Text)
....
....
def _input_to_MPA(value):
"""Convert the textual value for Compressive strength of concrete to MPA."""
return UnitUtils.ConvertToInternalUnits(float(value), UnitTypeId.Megapascals)
def get_or_create_concrete_material(contrainte, doc):
"""find or create the concrete material with the specific compressive strength requested by the user then return it's Id."""
c = int(UnitUtils.ConvertFromInternalUnits(contrainte , UnitTypeId.Megapascals))
print(float(c))
material_name = "Béton - Coulé sur place - Béton{}".format(c)
Materials = FilteredElementCollector(doc).WherePasses(ElementCategoryFilter(BuiltInCategory.OST_Materials))
material = next((m for m in Materials if m.Name == material_name), None)
if material:
m_Id = material.Id
else:
with Transaction(doc, 'Create concrete material') as t:
t.Start()
m_Id = Material.Create(doc, "Béton - Coulé sur place - Béton{}".format(c))
mat = doc.GetElement(m_Id)
mat.MaterialClass = "BĂ©ton"
mat.MaterialCategory = "BĂ©ton"
mat.Color = Color(192, 192, 192)
mat.Shininess = 128
mat.Smoothness = 50
asset = StructuralAsset("ConcreteStructuralAsset", StructuralAssetClass.Concrete)
asset.ConcreteCompression = contrainte
asset.Density = UnitUtils.ConvertToInternalUnits(2500, UnitTypeId.KilogramsPerCubicMeter)
asset.SetPoissonRatio(0.2)
asset.SetYoungModulus(UnitUtils.ConvertToInternalUnits(11000 * float(c)** (1 / 3), UnitTypeId.Megapascals))
struc = PropertySetElement.Create(doc, asset)
mat.SetMaterialAspectByPropertySet(MaterialAspect.Structural, struc.Id)
appar_Id = ElementId(177984)
mat.AppearanceAssetId = appar_Id
t.Commit()
return m_Id
As an example if I take
contrainte
= 27 MPA, the vale ofE
should be = 33000 MPA
I still have the wrong value as you can see below:
Thanks.