mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
You can now add and edit context dependent units including dimensional exponents
This commit is contained in:
@@ -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"])
|
||||
|
||||
Reference in New Issue
Block a user