2 Commits

Author SHA1 Message Date
Jedd Morgan 8c6a29a996 tidy up (#10) 2025-07-15 11:23:39 +01:00
Jedd Morgan 2e351b4254 feat: attach attributes that are on the element type level (#9)
* Added better property extraction

* property sets naming

* Get attributes from element type
2025-07-15 10:26:35 +01:00
3 changed files with 17 additions and 24 deletions
+1 -14
View File
@@ -54,20 +54,6 @@ def cmd_line_import() -> None:
json.dump({"success": False, "error": str(e)}, f)
def manual_import() -> None:
PROJECT_ID = "f3a42bdf24"
MODEL_ID = "0e23cfdea3"
SERVER_URL = "app.speckle.systems"
# FILE_PATH = "C:\\Users\\Jedd\\Desktop\\openshell\\60mins.ifc"
# FILE_PATH = "C:\\Users\\Jedd\\Desktop\\openshell\\hillside_house_meters.ifc"
# FILE_PATH = "C:\\Users\\Jedd\\Desktop\\openshell\\GRAPHISOFT_Archicad_Sample_Project-S-Office_v1.0_AC25.ifc" # noqa: E501
FILE_PATH = "C:\\Users\\Jedd\\Desktop\\openshell\\GRAPHISOFT_Archicad_Sample_Project-S-Office_v1.0_AC25.ifc" # noqa: E501
account = get_accounts_for_server(SERVER_URL)[0]
open_and_convert_file(FILE_PATH, PROJECT_ID, None, MODEL_ID, account)
def open_and_convert_file(
file_path: str,
project_id: str,
@@ -102,6 +88,7 @@ def open_and_convert_file(
model_id=model_id,
project_id=project_id,
message=version_message,
source_application="IFC",
)
version = client.version.create(create_version)
end = time.time()
+11 -8
View File
@@ -1,4 +1,5 @@
import time
from dataclasses import dataclass, field
from typing import cast
from ifcopenshell.entity_instance import entity_instance
@@ -16,13 +17,15 @@ from speckleifc.ifc_openshell_helpers import get_children
from speckleifc.render_material_proxy_manager import RenderMaterialProxyManager
@dataclass
class ImportJob:
def __init__(self, ifc_file: file):
self._ifc_file = ifc_file
self.cached_display_values: dict[int, list[Base]] = {}
self._render_material_manager = RenderMaterialProxyManager()
self.geometries_count = 0
self.geometries_used = 0
ifc_file: file
cached_display_values: dict[int, list[Base]] = field(default_factory=dict) # noqa: F821
_render_material_manager: RenderMaterialProxyManager = field(
default_factory=lambda: RenderMaterialProxyManager()
)
geometries_count: int = 0
geometries_used: int = 0
def convert_element(self, step_element: entity_instance) -> Base:
children = self._convert_children(step_element)
@@ -70,7 +73,7 @@ class ImportJob:
return root
def pre_process_geometry(self) -> None:
iterator = create_geometry_iterator(self._ifc_file)
iterator = create_geometry_iterator(self.ifc_file)
if not iterator.initialize():
raise SpeckleException(
"geometry iterator failed to initialize for the given file"
@@ -88,7 +91,7 @@ class ImportJob:
break
def _convert_project_tree(self) -> Base:
projects = self._ifc_file.by_type("IfcProject", False)
projects = self.ifc_file.by_type("IfcProject", False)
if len(projects) != 1:
raise SpeckleException("Expected exactly one IfcProject in file")
project = projects[0]
+5 -2
View File
@@ -6,7 +6,7 @@ from ifcopenshell.util.element import get_type
def extract_properties(element: entity_instance) -> dict[str, object]:
properties: dict[str, object] = {
"Attributes": get_attributes(element),
"Attributes": _get_attributes(element),
"Property Sets": _get_ifc_object_properties(element),
}
@@ -14,11 +14,14 @@ def extract_properties(element: entity_instance) -> dict[str, object]:
properties["Element Type Property Sets"] = _get_ifc_element_type_properties(
ifc_type,
)
properties["Element Type Attributes"] = _get_attributes(
ifc_type,
)
return properties
def get_attributes(element: entity_instance) -> dict[str, object]:
def _get_attributes(element: entity_instance) -> dict[str, object]:
return element.get_info(True, False, scalar_only=True)