Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 94dedacc5d | |||
| bafbcd8b87 | |||
| e97929470f | |||
| c8d62477cc | |||
| 8c6a29a996 | |||
| 2e351b4254 |
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user