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
import bonsai.core
import bonsai.core.geometry
from typing import Union, Optional
def disable_editing_boundary_geometry(context):
@@ -58,7 +59,7 @@ def disable_editing_boundary_geometry(context):
class Loader:
def __init__(self, operator=None):
def __init__(self, operator: Optional[bpy.types.Operator] = None):
self.operator = operator
self.ifc_file = None
self.logger = None
@@ -67,7 +68,7 @@ class Loader:
self.fallback_settings = self.load_fallback_settings()
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.
if not boundary.ConnectionGeometry:
return None
@@ -131,7 +132,7 @@ class Loader:
settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS)
return settings
def load_importer(self):
def load_importer(self) -> None:
self.ifc_file = tool.Ifc.get()
self.logger = logging.getLogger("ImportIFC")
ifc_import_settings = import_ifc.IfcImportSettings.factory(bpy.context, IfcStore.path, self.logger)
@@ -280,7 +281,7 @@ class SelectProjectBoundaries(bpy.types.Operator):
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"""
product_colors = {
"IfcWall": (0.7, 0.3, 0, 1),
@@ -21,6 +21,7 @@ import bpy
import bmesh
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.material
import ifcopenshell.util.element
import ifcopenshell.util.representation
import ifcopenshell.util.schema
+7 -3
View File
@@ -26,6 +26,7 @@ import collections.abc
import numpy as np
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.geometry
import ifcopenshell.api.grid
import ifcopenshell.api.pset
import ifcopenshell.geom
@@ -1555,12 +1556,14 @@ class Model(bonsai.core.tool.Model):
def add_body_representation(cls, obj: bpy.types.Object) -> None:
ifc_file = tool.Ifc.get()
body = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW")
representation = ifcopenshell.api.run(
"geometry.add_representation",
assert body
mesh = obj.data
assert isinstance(mesh, bpy.types.Mesh)
representation = ifcopenshell.api.geometry.add_representation(
ifc_file,
context=body,
blender_object=obj,
geometry=obj.data,
geometry=mesh,
coordinate_offset=tool.Geometry.get_cartesian_point_offset(obj),
total_items=tool.Geometry.get_total_representation_items(obj),
should_force_faceted_brep=tool.Geometry.should_force_faceted_brep(),
@@ -1569,6 +1572,7 @@ class Model(bonsai.core.tool.Model):
ifc_representation_class=None,
profile_set_usage=None,
)
assert representation
tool.Model.replace_object_ifc_representation(body, obj, representation)
@classmethod
@@ -613,7 +613,7 @@ class entity_instance:
include_identifier: bool = True,
recursive: bool = False,
return_type: type[dict] = dict,
ignore: Iterable[str] = (),
ignore: Sequence[str] = (),
) -> dict[str, Any]:
"""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.