This commit is contained in:
Andrej730
2025-03-05 14:56:29 +05:00
parent e1e51cbf26
commit 1c8ef176b1
4 changed files with 14 additions and 8 deletions
@@ -41,6 +41,7 @@ from bonsai.bim.module.model.decorator import ProfileDecorator
from bonsai.bim.module.boundary.decorator import BoundaryDecorator from bonsai.bim.module.boundary.decorator import BoundaryDecorator
import bonsai.core import bonsai.core
import bonsai.core.geometry import bonsai.core.geometry
from typing import Union, Optional
def disable_editing_boundary_geometry(context): def disable_editing_boundary_geometry(context):
@@ -58,7 +59,7 @@ def disable_editing_boundary_geometry(context):
class Loader: class Loader:
def __init__(self, operator=None): def __init__(self, operator: Optional[bpy.types.Operator] = None):
self.operator = operator self.operator = operator
self.ifc_file = None self.ifc_file = None
self.logger = None self.logger = None
@@ -67,7 +68,7 @@ class Loader:
self.fallback_settings = self.load_fallback_settings() self.fallback_settings = self.load_fallback_settings()
self.load_importer() self.load_importer()
def create_mesh(self, boundary): def create_mesh(self, boundary: ifcopenshell.entity_instance) -> Union[bpy.types.Mesh, None]:
# ConnectionGeometry is optional in IFC schema for some reasons. # ConnectionGeometry is optional in IFC schema for some reasons.
if not boundary.ConnectionGeometry: if not boundary.ConnectionGeometry:
return None return None
@@ -131,7 +132,7 @@ class Loader:
settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS) settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS)
return settings return settings
def load_importer(self): def load_importer(self) -> None:
self.ifc_file = tool.Ifc.get() self.ifc_file = tool.Ifc.get()
self.logger = logging.getLogger("ImportIFC") self.logger = logging.getLogger("ImportIFC")
ifc_import_settings = import_ifc.IfcImportSettings.factory(bpy.context, IfcStore.path, self.logger) ifc_import_settings = import_ifc.IfcImportSettings.factory(bpy.context, IfcStore.path, self.logger)
@@ -280,7 +281,7 @@ class SelectProjectBoundaries(bpy.types.Operator):
return {"FINISHED"} return {"FINISHED"}
def get_colour(ifc_boundary): def get_colour(ifc_boundary: ifcopenshell.entity_instance) -> tuple[float, float, float, float]:
"""Return a color depending on IfcClass given""" """Return a color depending on IfcClass given"""
product_colors = { product_colors = {
"IfcWall": (0.7, 0.3, 0, 1), "IfcWall": (0.7, 0.3, 0, 1),
@@ -21,6 +21,7 @@ import bpy
import bmesh import bmesh
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.api.material
import ifcopenshell.util.element import ifcopenshell.util.element
import ifcopenshell.util.representation import ifcopenshell.util.representation
import ifcopenshell.util.schema import ifcopenshell.util.schema
+7 -3
View File
@@ -26,6 +26,7 @@ import collections.abc
import numpy as np import numpy as np
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.api.geometry
import ifcopenshell.api.grid import ifcopenshell.api.grid
import ifcopenshell.api.pset import ifcopenshell.api.pset
import ifcopenshell.geom import ifcopenshell.geom
@@ -1555,12 +1556,14 @@ class Model(bonsai.core.tool.Model):
def add_body_representation(cls, obj: bpy.types.Object) -> None: def add_body_representation(cls, obj: bpy.types.Object) -> None:
ifc_file = tool.Ifc.get() ifc_file = tool.Ifc.get()
body = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW") body = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW")
representation = ifcopenshell.api.run( assert body
"geometry.add_representation", mesh = obj.data
assert isinstance(mesh, bpy.types.Mesh)
representation = ifcopenshell.api.geometry.add_representation(
ifc_file, ifc_file,
context=body, context=body,
blender_object=obj, blender_object=obj,
geometry=obj.data, geometry=mesh,
coordinate_offset=tool.Geometry.get_cartesian_point_offset(obj), coordinate_offset=tool.Geometry.get_cartesian_point_offset(obj),
total_items=tool.Geometry.get_total_representation_items(obj), total_items=tool.Geometry.get_total_representation_items(obj),
should_force_faceted_brep=tool.Geometry.should_force_faceted_brep(), should_force_faceted_brep=tool.Geometry.should_force_faceted_brep(),
@@ -1569,6 +1572,7 @@ class Model(bonsai.core.tool.Model):
ifc_representation_class=None, ifc_representation_class=None,
profile_set_usage=None, profile_set_usage=None,
) )
assert representation
tool.Model.replace_object_ifc_representation(body, obj, representation) tool.Model.replace_object_ifc_representation(body, obj, representation)
@classmethod @classmethod
@@ -613,7 +613,7 @@ class entity_instance:
include_identifier: bool = True, include_identifier: bool = True,
recursive: bool = False, recursive: bool = False,
return_type: type[dict] = dict, return_type: type[dict] = dict,
ignore: Iterable[str] = (), ignore: Sequence[str] = (),
) -> dict[str, Any]: ) -> dict[str, Any]:
"""More perfomant version of `.get_info()` but with limited arguments values.\n """More perfomant version of `.get_info()` but with limited arguments values.\n
Method has exactly the same signature as `.get_info()` but it doesn't support getting information non-recursively. Method has exactly the same signature as `.get_info()` but it doesn't support getting information non-recursively.