Skip to content

Commit 2066ebc

Browse files
committed
bbim, bcf - add simple operator to quickly load ifc file from bcf header
Example - https://imgur.com/a/rieFwNI
1 parent 795ebc0 commit 2066ebc

7 files changed

Lines changed: 64 additions & 3 deletions

File tree

src/bcf/bcf/v2/topic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,19 @@ def _save_document_references(self, destination_zip: ZipFileInterface) -> None:
230230
real_path = real_path.parent if path_part == ".." else real_path.joinpath(path_part)
231231
destination_zip.writestr(real_path.at, self.document_references[doc.referenced_document])
232232

233-
def extract_file(self, entity, outfile: Optional[Path] = None) -> Path:
233+
def extract_file(
234+
self, entity: Union[mdl.HeaderFile, mdl.BimSnippet, mdl.TopicDocumentReference], outfile: Optional[Path] = None
235+
) -> Union[Path, str, None]:
234236
"""Extracts an element with a file into a temporary directory
235237
236238
These include header files, bim snippets, document references, and
237239
viewpoint bitmaps. External reference are not downloaded. Instead, the
238240
URI reference is returned.
239241
240242
:param entity: The entity with a file reference to extract
241-
:type entity: bcf.v2.model.HeaderFile,bcf.v2.model.BimSnippet,bcf.v2.model.TopicDocumentReference
242243
:param outfile: If provided, save the header file to that location.
243244
Otherwise, a temporary directory is created and the filename is
244245
derived from the header's original filename.
245-
:type outfile: pathlib.Path,optional
246246
:return: The filepath of the extracted file. It may be a URL if the
247247
header file is external.
248248
:rtype: Path

src/bonsai/bonsai/bim/module/bcf/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
operator.EditBcfTopicName,
4242
operator.ExtractBcfFile,
4343
operator.LoadBcfComments,
44+
operator.LoadBcfHeaderIfcFile,
4445
operator.LoadBcfProject,
4546
operator.LoadBcfTopic,
4647
operator.LoadBcfTopics,

src/bonsai/bonsai/bim/module/bcf/operator.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,30 @@ def invoke(self, context, event):
12391239
return {"RUNNING_MODAL"}
12401240

12411241

1242+
class LoadBcfHeaderIfcFile(bpy.types.Operator):
1243+
bl_idname = "bim.load_bcf_header_ifc_file"
1244+
bl_label = "Load BCF Header IFC File"
1245+
bl_description = (
1246+
"Extract BCF Header IFC file and load it in current session."
1247+
"\n\nWarning. Current IFC and BCF sessions won't be saved, BCF file will be reloaded (if it's saved on disk)"
1248+
)
1249+
bl_options = {"REGISTER", "UNDO"}
1250+
index: bpy.props.IntProperty()
1251+
1252+
def execute(self, context):
1253+
bcfxml = bcfstore.BcfStore.get_bcfxml()
1254+
assert bcfxml
1255+
bcf_path = tool.Bcf.get_path()
1256+
1257+
topic = bcfxml.topics[context.scene.BCFProperties.active_topic.name]
1258+
entity = topic.header.file[self.index]
1259+
ifc_path = str(topic.extract_file(entity))
1260+
bpy.ops.bim.load_project(filepath=ifc_path)
1261+
if bcf_path:
1262+
bpy.ops.bim.load_bcf_project(filepath=bcf_path)
1263+
return {"FINISHED"}
1264+
1265+
12421266
class ExtractBcfFile(bpy.types.Operator):
12431267
bl_idname = "bim.extract_bcf_file"
12441268
bl_label = "Extract BCF Header File"

src/bonsai/bonsai/bim/module/bcf/ui.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ def draw(self, context):
140140
if f.is_external:
141141
row.operator("bim.open_uri", icon="URL", text="").uri = f.reference
142142
else:
143+
op = row.operator("bim.load_bcf_header_ifc_file", icon="FILE_REFRESH", text="")
144+
op.index = index
143145
op = row.operator("bim.extract_bcf_file", icon="FILE_FOLDER", text="")
144146
op.index = index
145147
op.entity_type = "HEADER_FILE"

src/bonsai/bonsai/core/tool.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ def get_container(cls, element): pass
7373
def get_relating_object(cls, related_element): pass
7474

7575

76+
@interface
77+
class Bcf:
78+
pass
79+
80+
7681
@interface
7782
class Blender:
7883
def activate_camera(cls, obj): pass

src/bonsai/bonsai/tool/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
1818

1919
from bonsai.tool.aggregate import Aggregate
20+
from bonsai.tool.bcf import Bcf
2021
from bonsai.tool.blender import Blender
2122
from bonsai.tool.boundary import Boundary
2223
from bonsai.tool.brick import Brick

src/bonsai/bonsai/tool/bcf.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Bonsai - OpenBIM Blender Add-on
2+
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
3+
#
4+
# This file is part of Bonsai.
5+
#
6+
# Bonsai is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Bonsai is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
18+
19+
import bonsai.core.tool
20+
import bonsai.tool as tool
21+
import bpy
22+
from typing import Any, Union, Optional
23+
24+
25+
class Bcf(bonsai.core.tool.Bcf):
26+
@classmethod
27+
def get_path(cls) -> str:
28+
return bpy.context.scene.BCFProperties.bcf_file

0 commit comments

Comments
 (0)