fix core.root.assign_class error after 3884403 #4719

This commit is contained in:
Andrej730
2024-05-24 14:23:10 +05:00
parent 6d887d593e
commit df15a37127
5 changed files with 20 additions and 7 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ def create_project(ifc, project, schema=None, template=None):
building = project.create_empty("My Building")
storey = project.create_empty("My Storey")
project.run_root_assign_class(obj=project_obj, ifc_class="IfcProject")
project.run_root_assign_class(obj=project_obj, ifc_class="IfcProject", should_add_representation=False)
project.run_unit_assign_scene_units()
model = project.run_context_add_context(context_type="Model", context_identifier="", target_view="", parent=0)
+6 -1
View File
@@ -63,11 +63,15 @@ def assign_class(
root: tool.Root,
obj: bpy.types.Object,
ifc_class: str,
context: ifcopenshell.entity_instance,
context: Optional[ifcopenshell.entity_instance] = None,
predefined_type: Optional[str] = None,
should_add_representation: bool = True,
ifc_representation_class: Optional[str] = None,
) -> ifcopenshell.entity_instance:
"""
Args:
context: is not optional if `should_add_representation` is True
"""
if ifc.get_entity(obj):
return
@@ -77,6 +81,7 @@ def assign_class(
ifc.link(element, obj)
if should_add_representation:
assert context, "Context is required for adding a representation"
root.run_geometry_add_representation(
obj=obj, context=context, ifc_representation_class=ifc_representation_class, profile_set_usage=None
)
+1 -1
View File
@@ -94,7 +94,7 @@ def hide_ports(ifc, system, element=None):
def add_port(ifc, system, element=None):
system.load_ports(element, system.get_ports(element))
obj = system.create_empty_at_cursor_with_element_orientation(element)
port = system.run_root_assign_class(obj=obj, ifc_class="IfcDistributionPort")
port = system.run_root_assign_class(obj=obj, ifc_class="IfcDistributionPort", should_add_representation=False)
ifc.run("system.assign_port", element=element, port=port)
+9 -3
View File
@@ -76,7 +76,9 @@ class TestCreateProject:
project.create_empty("My Site").should_be_called().will_return("site")
project.create_empty("My Building").should_be_called().will_return("building")
project.create_empty("My Storey").should_be_called().will_return("storey")
project.run_root_assign_class(obj="project", ifc_class="IfcProject").should_be_called()
project.run_root_assign_class(
obj="project", ifc_class="IfcProject", should_add_representation=False
).should_be_called()
project.run_unit_assign_scene_units().should_be_called()
self.check_contexts(project)
@@ -108,7 +110,9 @@ class TestCreateProject:
project.create_empty("My Site").should_be_called().will_return("site")
project.create_empty("My Building").should_be_called().will_return("building")
project.create_empty("My Storey").should_be_called().will_return("storey")
project.run_root_assign_class(obj="project", ifc_class="IfcProject").should_be_called()
project.run_root_assign_class(
obj="project", ifc_class="IfcProject", should_add_representation=False
).should_be_called()
project.run_unit_assign_scene_units().should_be_called()
self.check_contexts(project)
@@ -149,7 +153,9 @@ class TestCreateProject:
project.create_empty("My Site").should_be_called().will_return("site")
project.create_empty("My Building").should_be_called().will_return("building")
project.create_empty("My Storey").should_be_called().will_return("storey")
project.run_root_assign_class(obj="project", ifc_class="IfcProject").should_be_called()
project.run_root_assign_class(
obj="project", ifc_class="IfcProject", should_add_representation=False
).should_be_called()
project.run_unit_assign_scene_units().should_be_called()
self.check_contexts(project)
+3 -1
View File
@@ -146,7 +146,9 @@ class TestAddPort:
system.get_ports("element").should_be_called().will_return(["port"])
system.load_ports("element", ["port"]).should_be_called()
system.create_empty_at_cursor_with_element_orientation("element").should_be_called().will_return("obj")
system.run_root_assign_class(obj="obj", ifc_class="IfcDistributionPort").should_be_called().will_return("port")
system.run_root_assign_class(
obj="obj", ifc_class="IfcDistributionPort", should_add_representation=False
).should_be_called().will_return("port")
ifc.run("system.assign_port", element="element", port="port").should_be_called()
subject.add_port(ifc, system, element="element")