You can now add and edit context dependent units including dimensional exponents

This commit is contained in:
Dion Moult
2021-08-16 15:58:44 +10:00
parent 6ee0027f33
commit 6b7b81765c
6 changed files with 76 additions and 12 deletions
@@ -0,0 +1,14 @@
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"unit_type": "USERDEFINED", "name": "THINGAMAJIG", "dimensions": (0, 0, 0, 0, 0, 0, 0)}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
return self.file.create_entity(
"IfcContextDependentUnit",
Dimensions=self.file.createIfcDimensionalExponents(*self.settings["dimensions"]),
UnitType=self.settings["unit_type"],
Name=self.settings["name"],
)
@@ -7,4 +7,12 @@ class Usecase:
def execute(self):
for name, value in self.settings["attributes"].items():
if name == "Dimensions":
dimensions = self.settings["unit"].Dimensions
if len(self.file.get_inverse(dimensions)) > 1:
self.settings["unit"].Dimensions = self.file.createIfcDimensionalExponents(*value)
else:
for i, exponent in enumerate(value):
dimensions[i] = exponent
continue
setattr(self.settings["unit"], name, value)
@@ -1,3 +1,4 @@
import ifcopenshell.util.unit
import ifcopenshell.util.element
@@ -9,10 +10,12 @@ class Usecase():
self.settings[key] = value
def execute(self):
unit_assignment = self.file.by_type("IfcUnitAssignment")[0]
units = list(unit_assignment.Units)
units.remove(self.settings["unit"])
if not units:
return
unit_assignment.Units = units
unit_assignment = ifcopenshell.util.unit.get_unit_assignment(self.file)
if unit_assignment and self.settings["unit"] in unit_assignment.Units:
units = list(unit_assignment.Units)
units.remove(self.settings["unit"])
if units:
unit_assignment.Units = units
else:
self.file.remove(unit_assignment)
ifcopenshell.util.element.remove_deep(self.file, self.settings["unit"])