This commit is contained in:
Andrej730
2025-03-14 10:43:47 +05:00
parent 10ecac33b8
commit 0e8810c1f5
118 changed files with 869 additions and 1203 deletions
@@ -36,17 +36,14 @@ def add_conversion_based_unit(
kip, psi, ksi, minute, hour, day, btu, and fahrenheit.
:param name: A converted name chosen from the list above.
:type name: str
:param conversion_offset: If you want to offset the conversion further
by a set number, you may specify it here. For example, fahrenheit is
1.8 * kelvin - 459.67. The -459.67 is the conversion offset. Note
that this is just an example and you don't actually need to specify
that for fahrenheit as it's built into this API function. For
advanced users only.
:type conversion_offset: float, optional
:return: The new IfcConversionBasedUnit or
IfcConversionBasedUnitWithOffset
:rtype: ifcopenshell.entity_instance
Example:
@@ -59,28 +56,26 @@ def add_conversion_based_unit(
# Make it our default units, if we are doing an imperial building
ifcopenshell.api.unit.assign_unit(model, units=[length, area])
"""
settings = {"name": name, "conversion_offset": conversion_offset}
unit_type = ifcopenshell.util.unit.imperial_types.get(settings["name"], "USERDEFINED")
unit_type = ifcopenshell.util.unit.imperial_types.get(name, "USERDEFINED")
dimensions = ifcopenshell.util.unit.named_dimensions[unit_type]
exponents = file.createIfcDimensionalExponents(*dimensions)
si_name = ifcopenshell.util.unit.si_type_names[unit_type]
si_unit = file.createIfcSIUnit(UnitType=unit_type, Name=si_name)
conversion_real = ifcopenshell.util.unit.si_conversions.get(settings["name"], 1)
conversion_real = ifcopenshell.util.unit.si_conversions.get(name, 1)
value_component = file.create_entity("IfcReal", **{"wrappedValue": conversion_real})
conversion_factor = file.createIfcMeasureWithUnit(value_component, si_unit)
conversion_offset = settings["conversion_offset"]
if not conversion_offset:
conversion_offset = ifcopenshell.util.unit.si_offsets.get(settings["name"], 0)
conversion_offset = ifcopenshell.util.unit.si_offsets.get(name, 0)
if conversion_offset:
return file.createIfcConversionBasedUnitWithOffset(
exponents,
unit_type,
settings["name"],
name,
conversion_factor,
conversion_offset,
)
return file.createIfcConversionBasedUnit(exponents, unit_type, settings["name"], conversion_factor)
return file.createIfcConversionBasedUnit(exponents, unit_type, name, conversion_factor)