Replace all ifcopenshell.api.run with ifcopenshell.api static functions.

This commit is contained in:
Dion Moult
2024-06-28 12:36:31 +10:00
parent b5d613989e
commit 07060fc769
432 changed files with 4633 additions and 4856 deletions
@@ -17,7 +17,8 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import test.bootstrap
import ifcopenshell.api
import ifcopenshell.api.root
import ifcopenshell.api.project
# NOTE: supported only in IFC4+
@@ -29,11 +30,10 @@ class TestAssignDeclaration(test.bootstrap.IFC4):
return definitions
def test_assign_a_declaration(self):
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element_type2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
library = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProjectLibrary")
ifcopenshell.api.run(
"project.assign_declaration",
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
element_type2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
library = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProjectLibrary")
ifcopenshell.api.project.assign_declaration(
self.file,
definitions=[element_type, element_type2],
relating_context=library,
@@ -42,29 +42,29 @@ class TestAssignDeclaration(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcRelDeclares")) == 1
def test_doing_nothing_if_the_library_is_already_assigned(self):
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element_type2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
library = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProjectLibrary")
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[element_type, element_type2], relating_context=library
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
element_type2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
library = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProjectLibrary")
ifcopenshell.api.project.assign_declaration(
self.file, definitions=[element_type, element_type2], relating_context=library
)
total_elements = len([e for e in self.file])
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[element_type, element_type2], relating_context=library
ifcopenshell.api.project.assign_declaration(
self.file, definitions=[element_type, element_type2], relating_context=library
)
assert len([e for e in self.file]) == total_elements
def test_that_old_relationships_are_updated_if_they_still_contain_elements(self):
element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
library = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProjectLibrary")
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[element_type], relating_context=library
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
library = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProjectLibrary")
ifcopenshell.api.project.assign_declaration(
self.file, definitions=[element_type], relating_context=library
)
rel = self.file.by_type("IfcRelDeclares")[0]
element_type2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
element_type3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
ifcopenshell.api.run(
"project.assign_declaration", self.file, definitions=[element_type2, element_type3], relating_context=library
element_type2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
element_type3 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
ifcopenshell.api.project.assign_declaration(
self.file, definitions=[element_type2, element_type3], relating_context=library
)
assert len(rel.RelatedDefinitions) == 3