mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-12 14:33:28 +00:00
util.element.get_controls
This commit is contained in:
@@ -1169,6 +1169,25 @@ def get_groups(element: ifcopenshell.entity_instance) -> list[ifcopenshell.entit
|
|||||||
return groups
|
return groups
|
||||||
|
|
||||||
|
|
||||||
|
def get_controls(element: ifcopenshell.entity_instance) -> Generator[ifcopenshell.entity_instance]:
|
||||||
|
"""
|
||||||
|
Retrieves the controls of an element.
|
||||||
|
|
||||||
|
:param element: The IFC element
|
||||||
|
:return: Generator of IfcControl elements assigned to the element.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
.. code:: python
|
||||||
|
|
||||||
|
task = file.by_type("IfcTask")[0]
|
||||||
|
control = ifcopenshell.util.element.get_controls(task)[0]
|
||||||
|
"""
|
||||||
|
for rel in element.HasAssignments:
|
||||||
|
if rel.is_a("IfcRelAssignsToControl"):
|
||||||
|
yield rel.RelatingControl
|
||||||
|
|
||||||
|
|
||||||
def get_parent(element: ifcopenshell.entity_instance) -> Union[ifcopenshell.entity_instance, None]:
|
def get_parent(element: ifcopenshell.entity_instance) -> Union[ifcopenshell.entity_instance, None]:
|
||||||
"""Get the parent in the spatial heirarchy
|
"""Get the parent in the spatial heirarchy
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import ifcopenshell.api.control
|
||||||
|
import ifcopenshell.api.cost
|
||||||
import ifcopenshell.api.profile
|
import ifcopenshell.api.profile
|
||||||
import pytest
|
import pytest
|
||||||
import test.bootstrap
|
import test.bootstrap
|
||||||
@@ -926,6 +928,23 @@ class TestGetGroupsIFC2X3(test.bootstrap.IFC2X3, TestGetGroupsIFC4):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TestGetControls(test.bootstrap.IFC2X3):
|
||||||
|
def test_run(self):
|
||||||
|
model = self.file
|
||||||
|
element = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
|
||||||
|
control = ifcopenshell.api.cost.add_cost_schedule(model)
|
||||||
|
ifcopenshell.api.control.assign_control(model, related_objects=[element], relating_control=control)
|
||||||
|
assert list(subject.get_controls(element)) == [control]
|
||||||
|
|
||||||
|
|
||||||
|
class TestGetControlsIFC4(test.bootstrap.IFC4, TestGetControls):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TestGetControlsIFC4X3(test.bootstrap.IFC4X3, TestGetControls):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestGetAggregateIFC4(test.bootstrap.IFC4):
|
class TestGetAggregateIFC4(test.bootstrap.IFC4):
|
||||||
def test_getting_the_containing_aggregate_of_a_subelement(self):
|
def test_getting_the_containing_aggregate_of_a_subelement(self):
|
||||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||||
|
|||||||
Reference in New Issue
Block a user