This commit is contained in:
Andrej730
2025-02-18 15:18:23 +05:00
parent 83a351b1c7
commit 17642ca4e9
117 changed files with 683 additions and 1005 deletions
@@ -46,11 +46,8 @@ def add_derived_unit(
:type unit_type: str
:param userdefinedtype: The user defined type in case of choosing USERDEFINED, or None for no
user defined type.
:type userdefinedtype: str or None
:param attributes: a dictionary of attribute names and values.
:type attributes: dict
:return: The newly created IfcDerivedUnit
:rtype: ifcopenshell.entity_instance
Example:
@@ -69,15 +66,13 @@ def add_derived_unit(
#12=IfcDerivedUnit((#10,#11),.LINEARVELOCITY.,$)
"""
settings = {"unit_type": unit_type, "attributes": attributes}
derive_unit_elements = []
for named_unit in settings["attributes"]:
for named_unit in attributes:
derive_unit_elements.append(
file.create_entity("IfcDerivedUnitElement", Unit=named_unit, Exponent=settings["attributes"][named_unit])
file.create_entity("IfcDerivedUnitElement", Unit=named_unit, Exponent=attributes[named_unit])
)
return file.create_entity(
"IfcDerivedUnit", Elements=derive_unit_elements, UnitType=settings["unit_type"], UserDefinedType=userdefinedtype
"IfcDerivedUnit", Elements=derive_unit_elements, UnitType=unit_type, UserDefinedType=userdefinedtype
)
@@ -18,7 +18,7 @@
import ifcopenshell
import ifcopenshell.util.unit
from typing import Optional
from typing import Optional, Any
def assign_unit(
@@ -75,6 +75,9 @@ def assign_unit(
class Usecase:
file: ifcopenshell.file
settings: dict[str, Any]
def execute(self):
# We're going to refactor this to split unit creation and assignment
if self.settings["units"]:
@@ -26,13 +26,8 @@ def edit_derived_unit(file: ifcopenshell.file, unit: ifcopenshell.entity_instanc
IfcDerivedUnit, consult the IFC documentation.
:param unit: The IfcDerivedUnit entity you want to edit
:type unit: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict
:return: None
:rtype: None
"""
settings = {"unit": unit, "attributes": attributes or {}}
for name, value in settings["attributes"].items():
setattr(settings["unit"], name, value)
for name, value in attributes.items():
setattr(unit, name, value)
@@ -26,11 +26,8 @@ def edit_monetary_unit(file: ifcopenshell.file, unit: ifcopenshell.entity_instan
IfcMonetaryUnit, consult the IFC documentation.
:param unit: The IfcMonetaryUnit entity you want to edit
:type unit: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict
:return: None
:rtype: None
Example:
@@ -43,7 +40,5 @@ def edit_monetary_unit(file: ifcopenshell.file, unit: ifcopenshell.entity_instan
# Ah who are we kidding
ifcopenshell.api.unit.edit_monetary_unit(model, unit=zwl, attributes={"Currency": "USD"})
"""
settings = {"unit": unit, "attributes": attributes or {}}
for name, value in settings["attributes"].items():
setattr(settings["unit"], name, value)
for name, value in attributes.items():
setattr(unit, name, value)
@@ -29,11 +29,8 @@ def edit_named_unit(file: ifcopenshell.file, unit: ifcopenshell.entity_instance,
IfcNamedUnit, consult the IFC documentation.
:param unit: The IfcNamedUnit entity you want to edit
:type unit: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict
:return: None
:rtype: None
Example:
@@ -45,15 +42,13 @@ def edit_named_unit(file: ifcopenshell.file, unit: ifcopenshell.entity_instance,
# Uh, crates? Boxes? Whatever.
ifcopenshell.api.unit.edit_named_unit(model, unit=unit, attibutes={"Name": "CRATES"})
"""
settings = {"unit": unit, "attributes": attributes or {}}
for name, value in settings["attributes"].items():
for name, value in attributes.items():
if name == "Dimensions":
dimensions = settings["unit"].Dimensions
dimensions = unit.Dimensions
if len(file.get_inverse(dimensions)) > 1:
settings["unit"].Dimensions = file.createIfcDimensionalExponents(*value)
unit.Dimensions = file.createIfcDimensionalExponents(*value)
else:
for i, exponent in enumerate(value):
dimensions[i] = exponent
continue
setattr(settings["unit"], name, value)
setattr(unit, name, value)
@@ -23,9 +23,7 @@ def unassign_unit(file: ifcopenshell.file, units: Optional[list[ifcopenshell.ent
"""Unassigns units as default units for the project
:param units: A list of units to assign as project defaults.
:type units: list[ifcopenshell.entity_instance],optional
:return: None
:rtype: None
Example:
@@ -44,15 +42,12 @@ def unassign_unit(file: ifcopenshell.file, units: Optional[list[ifcopenshell.ent
# Actually, we don't need areas.
ifcopenshell.api.unit.unassign_unit(model, units=[area])
"""
settings = {"units": units}
unit_assignment = file.by_type("IfcUnitAssignment")
if not unit_assignment:
unit_assignments = file.by_type("IfcUnitAssignment")
if not unit_assignments:
return
unit_assignment = unit_assignment[0]
units = set(unit_assignment.Units or [])
units = units - set(settings["units"])
if units:
unit_assignment.Units = list(units)
return unit_assignment
unit_assignment = unit_assignments[0]
units_set = set(unit_assignment.Units or [])
units_set = units_set - set(units or [])
if units_set:
unit_assignment.Units = list(units_set)
file.remove(unit_assignment)