mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
New ifcopenshell.api.run syntax, and rename create_product to create_entity. See #1399.
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import importlib
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
def run(usecase_path, ifc_file=None, **settings):
|
||||
importlib.import_module(f"ifcopenshell.api.{usecase_path}")
|
||||
module, usecase = usecase_path.split(".")
|
||||
usecase_class = getattr(getattr(getattr(ifcopenshell.api, module), usecase), "Usecase")
|
||||
if ifc_file:
|
||||
return usecase_class(ifc_file, **settings).execute()
|
||||
return usecase_class(**settings).execute()
|
||||
@@ -1,6 +1,5 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.owner.create_owner_history as create_owner_history
|
||||
import ifcopenshell.api.owner.update_owner_history as update_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -32,7 +31,7 @@ class Usecase:
|
||||
related_objects.remove(self.settings["product"])
|
||||
if related_objects:
|
||||
decomposes.RelatedObjects = related_objects
|
||||
update_owner_history.Usecase(self.file, {"element": decomposes}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": decomposes})
|
||||
else:
|
||||
self.file.remove(decomposes)
|
||||
|
||||
@@ -40,13 +39,13 @@ class Usecase:
|
||||
related_objects = list(is_decomposed_by.RelatedObjects)
|
||||
related_objects.append(self.settings["product"])
|
||||
is_decomposed_by.RelatedObjects = related_objects
|
||||
update_owner_history.Usecase(self.file, {"element": is_decomposed_by}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": is_decomposed_by})
|
||||
else:
|
||||
is_decomposed_by = self.file.create_entity(
|
||||
"IfcRelAggregates",
|
||||
**{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": create_owner_history.Usecase(self.file).execute(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
"RelatedObjects": [self.settings["product"]],
|
||||
"RelatingObject": self.settings["relating_object"],
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import ifcopenshell.api.owner.update_owner_history as update_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase():
|
||||
class Usecase:
|
||||
def __init__(self, file, **settings):
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"product": None,
|
||||
"attributes": {}
|
||||
}
|
||||
self.settings = {"product": None, "attributes": {}}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
@@ -15,4 +12,4 @@ class Usecase():
|
||||
for name, value in self.settings["attributes"].items():
|
||||
setattr(self.settings["product"], name, value)
|
||||
if hasattr(self.settings["product"], "OwnerHistory"):
|
||||
update_owner_history.Usecase(self.file, {"element": self.settings["product"]}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": self.settings["product"]})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import ifcopenshell.api.owner.update_owner_history as update_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -35,4 +35,4 @@ class Usecase:
|
||||
)
|
||||
)
|
||||
self.settings["product"].RepresentationMaps = maps
|
||||
update_owner_history.Usecase(self.file, {"element": self.settings["product"]}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": self.settings["product"]})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import numpy as np
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.util.element
|
||||
import ifcopenshell.util.placement
|
||||
import ifcopenshell.api.owner.update_owner_history as update_owner_history
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -47,7 +47,7 @@ class Usecase:
|
||||
ifcopenshell.util.element.remove_deep(self.file, old)
|
||||
self.settings["product"].ObjectPlacement = placement
|
||||
|
||||
update_owner_history.Usecase(self.file, {"element": self.settings["product"]}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": self.settings["product"]})
|
||||
|
||||
for settings in dependent_objects:
|
||||
self.settings = settings
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import ifcopenshell.api.geometry.remove_representation as remove_representation
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
@@ -53,4 +53,4 @@ class Usecase:
|
||||
for item in mapped_representations:
|
||||
self.unassign_product_representation(item["product"], item["representation"])
|
||||
for representation in just_representations:
|
||||
remove_representation.Usecase(self.file, {"representation": representation}).execute()
|
||||
ifcopenshell.api.run("owner.remove_representation", self.file, **{"representation": representation})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.owner.create_owner_history as create_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -12,6 +12,6 @@ class Usecase:
|
||||
def execute(self):
|
||||
return self.file.create_entity("IfcGroup", **{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": create_owner_history.Usecase(self.file).execute(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
"Name": "Unnamed"
|
||||
})
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.owner.create_owner_history as create_owner_history
|
||||
import ifcopenshell.api.owner.update_owner_history as update_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -17,7 +16,7 @@ class Usecase:
|
||||
if not self.settings["group"].IsGroupedBy:
|
||||
return self.file.create_entity("IfcRelAssignsToGroup", **{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": create_owner_history.Usecase(self.file).execute(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
"RelatedObjects": [self.settings["product"]],
|
||||
"RelatingGroup": self.settings["group"]
|
||||
})
|
||||
@@ -25,4 +24,4 @@ class Usecase:
|
||||
related_objects = set(rel.RelatedObjects) or set()
|
||||
related_objects.add(self.settings["product"])
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
update_owner_history.Usecase(self.file, {"element": rel}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.owner.update_owner_history as update_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -20,6 +20,6 @@ class Usecase:
|
||||
related_objects.remove(self.settings["product"])
|
||||
if len(related_objects):
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
update_owner_history.Usecase(self.file, {"element": rel}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
|
||||
else:
|
||||
self.file.remove(rel)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import time
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.owner.create_owner_history as create_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -14,7 +14,9 @@ class Usecase:
|
||||
self.settings["person"] = ifcopenshell.api.owner.settings.get_person()
|
||||
self.settings["organisation"] = ifcopenshell.api.owner.settings.get_organisation()
|
||||
if not self.settings["element"].OwnerHistory:
|
||||
self.settings["element"].OwnerHistory = create_owner_history.Usecase(self.file, self.settings).execute()
|
||||
self.settings["element"].OwnerHistory = ifcopenshell.api.run(
|
||||
"owner.create_owner_history", self.file, **self.settings
|
||||
)
|
||||
return self.settings["element"].OwnerHistory
|
||||
if len(self.file.get_inverse(self.settings["element"].OwnerHistory)) > 1:
|
||||
old_history = self.settings["element"].OwnerHistory
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.owner.create_owner_history as create_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -16,7 +16,7 @@ class Usecase:
|
||||
def execute(self):
|
||||
element = self.file.create_entity(self.settings["ifc_class"], **{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": create_owner_history.Usecase(self.file).execute()
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file)
|
||||
})
|
||||
element.Name = self.settings["name"] or None
|
||||
if self.settings["predefined_type"]:
|
||||
@@ -1,5 +1,4 @@
|
||||
import ifcopenshell.api.geometry.unassign_representation as unassign_representation
|
||||
import ifcopenshell.api.geometry.remove_representation as remove_representation
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -19,9 +18,9 @@ class Usecase:
|
||||
elif self.settings["product"].is_a("IfcTypeProduct"):
|
||||
representations = [rm.MappedRepresentation for rm in self.settings["product"].RepresentationMaps or []]
|
||||
for representation in representations:
|
||||
unassign_representation.Usecase(
|
||||
self.file, {"product": self.settings["product"], "representation": representation}
|
||||
).execute()
|
||||
remove_representation.Usecase(self.file, {"representation": representation}).execute()
|
||||
ifcopenshell.api.run("owner.unassign_representation",
|
||||
self.file, **{"product": self.settings["product"], "representation": representation}
|
||||
)
|
||||
ifcopenshell.api.run("owner.remove_representation", self.file, **{"representation": representation})
|
||||
# TODO: remove object placement and other relationships
|
||||
self.file.remove(self.settings["product"])
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.owner.create_owner_history as create_owner_history
|
||||
import ifcopenshell.api.owner.update_owner_history as update_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -25,7 +24,7 @@ class Usecase:
|
||||
related_elements.remove(self.settings["product"])
|
||||
if related_elements:
|
||||
contained_in_structure[0].RelatedElements = related_elements
|
||||
update_owner_history.Usecase(self.file, {"element": contained_in_structure[0]}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": contained_in_structure[0]})
|
||||
else:
|
||||
self.file.remove(contained_in_structure[0])
|
||||
|
||||
@@ -33,13 +32,13 @@ class Usecase:
|
||||
related_elements = list(contains_elements[0].RelatedElements)
|
||||
related_elements.append(self.settings["product"])
|
||||
contains_elements[0].RelatedElements = related_elements
|
||||
update_owner_history.Usecase(self.file, {"element": contains_elements[0]}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": contains_elements[0]})
|
||||
else:
|
||||
contains_elements = self.file.create_entity(
|
||||
"IfcRelContainedInSpatialStructure",
|
||||
**{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": create_owner_history.Usecase(self.file).execute(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
"RelatedElements": [self.settings["product"]],
|
||||
"RelatingStructure": self.settings["relating_structure"],
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.owner.update_owner_history as update_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -17,6 +17,6 @@ class Usecase:
|
||||
related_elements.remove(self.settings["product"])
|
||||
if related_elements:
|
||||
contained_in_structure[0].RelatedElements = related_elements
|
||||
update_owner_history.Usecase(self.file, {"element": contained_in_structure[0]}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": contained_in_structure[0]})
|
||||
else:
|
||||
self.file.remove(contained_in_structure)
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.owner.create_owner_history as create_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -12,7 +12,7 @@ class Usecase:
|
||||
def execute(self):
|
||||
return self.file.create_entity("IfcStructuralAnalysisModel", **{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": create_owner_history.Usecase(self.file).execute(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
"Name": "Unnamed",
|
||||
"PredefinedType": "LOADING_3D"
|
||||
})
|
||||
|
||||
+3
-4
@@ -1,6 +1,5 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.owner.create_owner_history as create_owner_history
|
||||
import ifcopenshell.api.owner.update_owner_history as update_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -17,7 +16,7 @@ class Usecase:
|
||||
if not self.settings["structural_analysis_model"].IsGroupedBy:
|
||||
return self.file.create_entity("IfcRelAssignsToGroup", **{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": create_owner_history.Usecase(self.file).execute(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
"RelatedObjects": [self.settings["product"]],
|
||||
"RelatingGroup": self.settings["structural_analysis_model"]
|
||||
})
|
||||
@@ -25,4 +24,4 @@ class Usecase:
|
||||
related_objects = set(rel.RelatedObjects) or set()
|
||||
related_objects.add(self.settings["product"])
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
update_owner_history.Usecase(self.file, {"element": rel}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.owner.update_owner_history as update_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -20,6 +20,6 @@ class Usecase:
|
||||
related_objects.remove(self.settings["product"])
|
||||
if len(related_objects):
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
update_owner_history.Usecase(self.file, {"element": rel}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
|
||||
else:
|
||||
self.file.remove(rel)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.owner.create_owner_history as create_owner_history
|
||||
import ifcopenshell.api.owner.update_owner_history as update_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -34,7 +33,7 @@ class Usecase:
|
||||
related_objects.remove(self.settings["related_object"])
|
||||
if related_objects:
|
||||
is_typed_by[0].RelatedObjects = related_objects
|
||||
update_owner_history.Usecase(self.file, {"element": is_typed_by[0]}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": is_typed_by[0]})
|
||||
else:
|
||||
self.file.remove(is_typed_by[0])
|
||||
|
||||
@@ -42,13 +41,13 @@ class Usecase:
|
||||
related_objects = list(types[0].RelatedObjects)
|
||||
related_objects.append(self.settings["related_object"])
|
||||
types[0].RelatedObjects = related_objects
|
||||
update_owner_history.Usecase(self.file, {"element": types[0]}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": types[0]})
|
||||
else:
|
||||
types = self.file.create_entity(
|
||||
"IfcRelDefinesByType",
|
||||
**{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": create_owner_history.Usecase(self.file).execute(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
"RelatedObjects": [self.settings["related_object"]],
|
||||
"RelatingType": self.settings["relating_type"],
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.owner.update_owner_history as update_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -28,6 +28,6 @@ class Usecase:
|
||||
related_objects.remove(self.settings["related_object"])
|
||||
if related_objects:
|
||||
is_typed_by.RelatedObjects = related_objects
|
||||
update_owner_history.Usecase(self.file, {"element": is_typed_by}).execute()
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": is_typed_by})
|
||||
else:
|
||||
self.file.remove(is_typed_by)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.owner.create_owner_history as create_owner_history
|
||||
import ifcopenshell.api
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -12,7 +12,7 @@ class Usecase:
|
||||
def execute(self):
|
||||
self.file.create_entity("IfcRelVoidsElement", **{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": create_owner_history.Usecase(self.file).execute(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
"RelatingBuildingElement": self.settings["element"],
|
||||
"RelatedOpeningElement": self.settings["opening"]
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user