mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 18:16:40 +00:00
common method for iterating over element's representations
This commit is contained in:
@@ -77,12 +77,7 @@ class RepresentationsData:
|
||||
if bpy.context.active_object.data and hasattr(bpy.context.active_object.data, "BIMMeshProperties"):
|
||||
active_representation_id = bpy.context.active_object.data.BIMMeshProperties.ifc_definition_id
|
||||
|
||||
representations = []
|
||||
if element.is_a("IfcProduct") and element.Representation:
|
||||
representations = element.Representation.Representations
|
||||
elif element.is_a("IfcTypeProduct"):
|
||||
representations = [rm.MappedRepresentation for rm in element.RepresentationMaps or []]
|
||||
for representation in representations:
|
||||
for representation in tool.Geometry.get_representations_iter(element):
|
||||
representation_type = representation.RepresentationType
|
||||
if representation_type == "MappedRepresentation":
|
||||
representation_type = representation.Items[0].MappingSource.MappedRepresentation.RepresentationType
|
||||
|
||||
@@ -41,6 +41,7 @@ from math import radians, pi
|
||||
from mathutils import Vector, Matrix
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
from typing import Union, Iterable, Optional, Literal
|
||||
from typing import Iterator
|
||||
|
||||
|
||||
class Geometry(blenderbim.core.tool.Geometry):
|
||||
@@ -345,18 +346,22 @@ class Geometry(blenderbim.core.tool.Geometry):
|
||||
getattr(subcontext, "TargetView", None),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_representations_iter(cls, element: ifcopenshell.entity_instance) -> Iterator[ifcopenshell.entity_instance]:
|
||||
if element.is_a("IfcProduct") and (rep := element.Representation):
|
||||
for r in rep.Representations:
|
||||
yield r
|
||||
elif element.is_a("IfcTypeProduct") and (maps := element.RepresentationMaps):
|
||||
for r in maps:
|
||||
yield r.MappedRepresentation
|
||||
|
||||
@classmethod
|
||||
def get_representation_by_context(
|
||||
cls, element: ifcopenshell.entity_instance, context: ifcopenshell.entity_instance
|
||||
) -> Union[ifcopenshell.entity_instance, None]:
|
||||
if element.is_a("IfcProduct") and element.Representation:
|
||||
for r in element.Representation.Representations:
|
||||
if r.ContextOfItems == context:
|
||||
return r
|
||||
elif element.is_a("IfcTypeProduct") and element.RepresentationMaps:
|
||||
for r in element.RepresentationMaps:
|
||||
if r.MappedRepresentation.ContextOfItems == context:
|
||||
return r.MappedRepresentation
|
||||
for r in cls.get_representations_iter(element):
|
||||
if r.ContextOfItems == context:
|
||||
return r
|
||||
|
||||
@classmethod
|
||||
def get_cartesian_point_coordinate_offset(cls, obj: bpy.types.Object) -> Union[Vector, None]:
|
||||
|
||||
Reference in New Issue
Block a user