mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 10:33:20 +00:00
typing
This commit is contained in:
@@ -35,9 +35,7 @@ def add_context_dependent_unit(
|
||||
sensible normal unit for. In that case, firstly stop whatever you're
|
||||
doing and have a hard think about your life, and then if life really
|
||||
is going that badly for you, check out the IFC docs for IfcUnitEnum.
|
||||
:type unit_type: str
|
||||
:param name: Give your unit a name. X what? X bananas?
|
||||
:type name: str
|
||||
:param dimensions: Units typically measure one of 7 fundamental physical
|
||||
dimensions: length, mass, time, electric current, temperature,
|
||||
substance amount, or luminous intensity. These are represented as a
|
||||
@@ -46,9 +44,7 @@ def add_context_dependent_unit(
|
||||
where as an area unit is (2, 0, 0, 0, 0, 0, 0). A unit of meters per
|
||||
second is (1, 0, -1, 0, 0, 0, 0). For context dependent units, it is
|
||||
recommended to leave this as the default of (0, 0, 0, 0, 0, 0, 0).
|
||||
:type dimensions: list[int]
|
||||
:return: The new IfcContextDependentUnit
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
|
||||
Example:
|
||||
|
||||
@@ -57,11 +53,9 @@ def add_context_dependent_unit(
|
||||
# Boxes of things
|
||||
ifcopenshell.api.unit.add_context_dependent_unit(model, name="BOXES")
|
||||
"""
|
||||
settings = {"unit_type": unit_type, "name": name, "dimensions": dimensions}
|
||||
|
||||
return file.create_entity(
|
||||
"IfcContextDependentUnit",
|
||||
Dimensions=file.createIfcDimensionalExponents(*settings["dimensions"]),
|
||||
UnitType=settings["unit_type"],
|
||||
Name=settings["name"],
|
||||
Dimensions=file.createIfcDimensionalExponents(*dimensions),
|
||||
UnitType=unit_type,
|
||||
Name=name,
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -26,9 +26,7 @@ def add_monetary_unit(file: ifcopenshell.file, currency: str = "DOLLARYDOO") ->
|
||||
USD, GBP, AUD, MYR, etc.
|
||||
|
||||
:param currency: The currency code
|
||||
:type currency: str
|
||||
:return: The newly created IfcMonetaryUnit
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
|
||||
Example:
|
||||
|
||||
@@ -41,6 +39,4 @@ def add_monetary_unit(file: ifcopenshell.file, currency: str = "DOLLARYDOO") ->
|
||||
# Make it our default currency
|
||||
ifcopenshell.api.unit.assign_unit(model, units=[zwl])
|
||||
"""
|
||||
settings = {"currency": currency}
|
||||
|
||||
return file.create_entity("IfcMonetaryUnit", settings["currency"])
|
||||
return file.create_entity("IfcMonetaryUnit", currency)
|
||||
|
||||
@@ -40,12 +40,9 @@ def add_si_unit(
|
||||
|
||||
:param unit_type: A type of unit chosen from the list above. For
|
||||
example, choosing LENGTHUNIT will give you a metre.
|
||||
:type unit_type: str
|
||||
:param prefix: A prefix chosen from the list above, or None for no
|
||||
prefix.
|
||||
:type prefix: str,optional
|
||||
:return: The newly created IfcSIUnit
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
|
||||
Example:
|
||||
|
||||
@@ -58,7 +55,5 @@ def add_si_unit(
|
||||
# Make it our default units, if we are doing a metric building
|
||||
ifcopenshell.api.unit.assign_unit(model, units=[length, area])
|
||||
"""
|
||||
settings = {"unit_type": unit_type, "prefix": prefix}
|
||||
|
||||
name = ifcopenshell.util.unit.si_type_names.get(settings["unit_type"], None)
|
||||
return file.create_entity("IfcSIUnit", UnitType=settings["unit_type"], Name=name, Prefix=settings["prefix"])
|
||||
name = ifcopenshell.util.unit.si_type_names.get(unit_type, None)
|
||||
return file.create_entity("IfcSIUnit", UnitType=unit_type, Name=name, Prefix=prefix)
|
||||
|
||||
@@ -27,9 +27,7 @@ def remove_unit(file: ifcopenshell.file, unit: ifcopenshell.entity_instance) ->
|
||||
defined quantities in the model completely lose their meaning.
|
||||
|
||||
:param unit: The unit element to remove
|
||||
:type unit: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
|
||||
@@ -41,14 +39,12 @@ def remove_unit(file: ifcopenshell.file, unit: ifcopenshell.entity_instance) ->
|
||||
# Yeah maybe not.
|
||||
ifcopenshell.api.unit.remove_unit(model, unit=unit)
|
||||
"""
|
||||
settings = {"unit": unit}
|
||||
|
||||
unit_assignment = ifcopenshell.util.unit.get_unit_assignment(file)
|
||||
if unit_assignment and settings["unit"] in unit_assignment.Units:
|
||||
if unit_assignment and unit in unit_assignment.Units:
|
||||
units = list(unit_assignment.Units)
|
||||
units.remove(settings["unit"])
|
||||
units.remove(unit)
|
||||
if units:
|
||||
unit_assignment.Units = units
|
||||
else:
|
||||
file.remove(unit_assignment)
|
||||
ifcopenshell.util.element.remove_deep(file, settings["unit"])
|
||||
ifcopenshell.util.element.remove_deep(file, unit)
|
||||
|
||||
Reference in New Issue
Block a user