6 Commits

Author SHA1 Message Date
Jedd Morgan 94dedacc5d Update README.md (#15) 2025-07-28 10:39:10 +01:00
Sebastian Witt bafbcd8b87 Rendermaterials inherit material names instead of type + unique id (#14) 2025-07-22 15:57:50 +01:00
Jedd Morgan e97929470f ruff (#12) 2025-07-15 17:33:43 +01:00
Jedd Morgan c8d62477cc Add null check (#11) 2025-07-15 16:25:46 +01:00
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
5 changed files with 27 additions and 26 deletions
+4
View File
@@ -1 +1,5 @@
# ifc-openshell-file-importer
⚠ We have moved this code into the specklepy repo - https://github.com/specklesystems/specklepy/tree/main/src/speckleifc ⚠
Please open new issues and PRs there
+2 -15
View File
@@ -5,7 +5,7 @@ from argparse import ArgumentParser
from os import getenv
from specklepy.core.api.client import SpeckleClient
from specklepy.core.api.credentials import Account, get_accounts_for_server
from specklepy.core.api.credentials import Account
from specklepy.core.api.inputs.version_inputs import CreateVersionInput
from specklepy.core.api.models.current import Version
from specklepy.core.api.operations import send
@@ -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()
@@ -15,6 +15,8 @@ def _create_iterator_settings() -> settings:
ifc_settings.set("use-world-coords", True)
# Tiny performance improvement,
ifc_settings.set("no-wire-intersection-check", True)
# Rendermaterials inherit the material names instead of type + unique id
ifc_settings.set("use-material-names", True)
# IfcOpenshell defaults to 0.001mm here, which leads to very dense meshes.
# lowering the mesh quality a bit here leads to meshes
+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]
+8 -3
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)
@@ -39,7 +42,9 @@ def _get_ifc_object_properties(element: entity_instance) -> dict[str, object]:
if not rel.is_a("IfcRelDefinesByProperties"):
continue
definition: entity_instance = rel.RelatingPropertyDefinition
definition: entity_instance | None = rel.RelatingPropertyDefinition
if not definition:
continue
if not definition.is_a("IfcPropertySet"):
continue