mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
assign_structural_analysis_model to support batching
This commit is contained in:
@@ -43,7 +43,7 @@ def assign_structural_analysis_model(
|
|||||||
ifc.run(
|
ifc.run(
|
||||||
"structural.assign_structural_analysis_model",
|
"structural.assign_structural_analysis_model",
|
||||||
**{
|
**{
|
||||||
"product": ifc.get().by_id(product_.BIMObjectProperties.ifc_definition_id),
|
"products": [ifc.get().by_id(product_.BIMObjectProperties.ifc_definition_id)],
|
||||||
"structural_analysis_model": ifc.get().by_id(structural_analysis_model),
|
"structural_analysis_model": ifc.get().by_id(structural_analysis_model),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -110,7 +110,7 @@ def unassign_structural_analysis_model(
|
|||||||
ifc.run(
|
ifc.run(
|
||||||
"structural.unassign_structural_analysis_model",
|
"structural.unassign_structural_analysis_model",
|
||||||
**{
|
**{
|
||||||
"product": ifc.get().by_id(product_.BIMObjectProperties.ifc_definition_id),
|
"products": [ifc.get().by_id(product_.BIMObjectProperties.ifc_definition_id)],
|
||||||
"structural_analysis_model": ifc.get().by_id(structural_analysis_model),
|
"structural_analysis_model": ifc.get().by_id(structural_analysis_model),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
+6
-27
@@ -17,43 +17,22 @@
|
|||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
import ifcopenshell.api.group
|
||||||
import ifcopenshell.api.owner
|
import ifcopenshell.api.owner
|
||||||
import ifcopenshell.guid
|
import ifcopenshell.guid
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
|
||||||
def assign_structural_analysis_model(
|
def assign_structural_analysis_model(
|
||||||
file: ifcopenshell.file,
|
file: ifcopenshell.file,
|
||||||
product: ifcopenshell.entity_instance,
|
products: list[ifcopenshell.entity_instance],
|
||||||
structural_analysis_model: ifcopenshell.entity_instance,
|
structural_analysis_model: ifcopenshell.entity_instance,
|
||||||
) -> ifcopenshell.entity_instance:
|
) -> Union[ifcopenshell.entity_instance, None]:
|
||||||
"""Assigns a load or structural member to an analysis model
|
"""Assigns a load or structural member to an analysis model
|
||||||
|
|
||||||
:param product: The structural element that is part of the analysis.
|
:param products: The structural elements that is part of the analysis.
|
||||||
:type product: ifcopenshell.entity_instance
|
|
||||||
:param structural_analysis_model: The IfcStructuralAnalysisModel that
|
:param structural_analysis_model: The IfcStructuralAnalysisModel that
|
||||||
the structural element is related to.
|
the structural element is related to.
|
||||||
:type structural_analysis_model: ifcopenshell.entity_instance
|
|
||||||
:return: The IfcRelAssignsToGroup relationship
|
:return: The IfcRelAssignsToGroup relationship
|
||||||
:rtype: ifcopenshell.entity_instance
|
|
||||||
"""
|
"""
|
||||||
settings = {
|
return ifcopenshell.api.group.assign_group(file, products, structural_analysis_model)
|
||||||
"product": product,
|
|
||||||
"structural_analysis_model": structural_analysis_model,
|
|
||||||
}
|
|
||||||
|
|
||||||
if not settings["structural_analysis_model"].IsGroupedBy:
|
|
||||||
return file.create_entity(
|
|
||||||
"IfcRelAssignsToGroup",
|
|
||||||
**{
|
|
||||||
"GlobalId": ifcopenshell.guid.new(),
|
|
||||||
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(file),
|
|
||||||
"RelatedObjects": [settings["product"]],
|
|
||||||
"RelatingGroup": settings["structural_analysis_model"],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
rel = settings["structural_analysis_model"].IsGroupedBy[0]
|
|
||||||
related_objects = set(rel.RelatedObjects) or set()
|
|
||||||
related_objects.add(settings["product"])
|
|
||||||
rel.RelatedObjects = list(related_objects)
|
|
||||||
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
|
|
||||||
return rel
|
|
||||||
|
|||||||
+4
-23
@@ -17,40 +17,21 @@
|
|||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
|
import ifcopenshell.api.group
|
||||||
import ifcopenshell.api.owner
|
import ifcopenshell.api.owner
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
|
|
||||||
|
|
||||||
def unassign_structural_analysis_model(
|
def unassign_structural_analysis_model(
|
||||||
file: ifcopenshell.file,
|
file: ifcopenshell.file,
|
||||||
product: ifcopenshell.entity_instance,
|
products: list[ifcopenshell.entity_instance],
|
||||||
structural_analysis_model: ifcopenshell.entity_instance,
|
structural_analysis_model: ifcopenshell.entity_instance,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Removes a relationship between a structural element and the analysis model
|
"""Removes a relationship between a structural element and the analysis model
|
||||||
|
|
||||||
:param product: The structural element that is part of the analysis.
|
:param products: The structural elements that is part of the analysis.
|
||||||
:type product: ifcopenshell.entity_instance
|
|
||||||
:param structural_analysis_model: The IfcStructuralAnalysisModel that
|
:param structural_analysis_model: The IfcStructuralAnalysisModel that
|
||||||
the structural element is related to.
|
the structural element is related to.
|
||||||
:type structural_analysis_model: ifcopenshell.entity_instance
|
|
||||||
:return: None
|
:return: None
|
||||||
:rtype: None
|
|
||||||
"""
|
"""
|
||||||
settings = {
|
ifcopenshell.api.group.unassign_group(file, products, structural_analysis_model)
|
||||||
"product": product,
|
|
||||||
"structural_analysis_model": structural_analysis_model,
|
|
||||||
}
|
|
||||||
|
|
||||||
if not settings["structural_analysis_model"].IsGroupedBy:
|
|
||||||
return
|
|
||||||
rel = settings["structural_analysis_model"].IsGroupedBy[0]
|
|
||||||
related_objects = set(rel.RelatedObjects) or set()
|
|
||||||
related_objects.remove(settings["product"])
|
|
||||||
if len(related_objects):
|
|
||||||
rel.RelatedObjects = list(related_objects)
|
|
||||||
ifcopenshell.api.owner.update_owner_history(file, **{"element": rel})
|
|
||||||
else:
|
|
||||||
history = rel.OwnerHistory
|
|
||||||
file.remove(rel)
|
|
||||||
if history:
|
|
||||||
ifcopenshell.util.element.remove_deep2(file, history)
|
|
||||||
|
|||||||
+3
-2
@@ -29,12 +29,13 @@ class TestAssignStructuralAnalysisModel(test.bootstrap.IFC4):
|
|||||||
)
|
)
|
||||||
rel = ifcopenshell.api.structural.assign_structural_analysis_model(
|
rel = ifcopenshell.api.structural.assign_structural_analysis_model(
|
||||||
self.file,
|
self.file,
|
||||||
product=product,
|
products=[product],
|
||||||
structural_analysis_model=subject,
|
structural_analysis_model=subject,
|
||||||
)
|
)
|
||||||
|
assert rel
|
||||||
assert rel.is_a("IfcRelAssignsToGroup")
|
assert rel.is_a("IfcRelAssignsToGroup")
|
||||||
assert rel.RelatingGroup == subject
|
assert rel.RelatingGroup == subject
|
||||||
assert product in rel.RelatedObjects
|
assert rel.RelatedObjects == (product,)
|
||||||
|
|
||||||
|
|
||||||
class TestAssignStructuralAnalysisModelIFC2X3(test.bootstrap.IFC2X3, TestAssignStructuralAnalysisModel):
|
class TestAssignStructuralAnalysisModelIFC2X3(test.bootstrap.IFC2X3, TestAssignStructuralAnalysisModel):
|
||||||
|
|||||||
+2
-2
@@ -29,12 +29,12 @@ class TestUnassignStructuralAnalysisModel(test.bootstrap.IFC4):
|
|||||||
)
|
)
|
||||||
ifcopenshell.api.structural.assign_structural_analysis_model(
|
ifcopenshell.api.structural.assign_structural_analysis_model(
|
||||||
self.file,
|
self.file,
|
||||||
product=product,
|
products=[product],
|
||||||
structural_analysis_model=subject,
|
structural_analysis_model=subject,
|
||||||
)
|
)
|
||||||
ifcopenshell.api.structural.unassign_structural_analysis_model(
|
ifcopenshell.api.structural.unassign_structural_analysis_model(
|
||||||
self.file,
|
self.file,
|
||||||
product=product,
|
products=[product],
|
||||||
structural_analysis_model=subject,
|
structural_analysis_model=subject,
|
||||||
)
|
)
|
||||||
models = self.file.by_type("IfcStructuralAnalysisModel")
|
models = self.file.by_type("IfcStructuralAnalysisModel")
|
||||||
|
|||||||
Reference in New Issue
Block a user