Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 5e815e7

Browse files
committed
You can now append object types from an IFC project library to your active project
1 parent e7b153c commit 5e815e7

5 files changed

Lines changed: 50 additions & 11 deletions

File tree

src/blenderbim/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ endif
188188
mkdir dist/working
189189
cd dist/working && wget https://raw.githubusercontent.com/jsGanttImproved/jsgantt-improved/master/dist/jsgantt.js
190190
cd dist/working && wget https://raw.githubusercontent.com/jsGanttImproved/jsgantt-improved/master/dist/jsgantt.css
191-
cd dist/working && mv jsgantt* dist/blenderbim/bim/data/gantt/
191+
cp dist/working/jsgantt* dist/blenderbim/bim/data/gantt/
192192
rm -rf dist/working
193193

194194
# Required by IFCDiff

src/blenderbim/blenderbim/bim/module/project/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
operator.AssignLibraryDeclaration,
1313
operator.UnassignLibraryDeclaration,
1414
operator.SaveLibraryFile,
15+
operator.AppendLibraryElement,
1516
prop.LibraryElement,
1617
prop.BIMProjectProperties,
1718
ui.BIM_PT_project,

src/blenderbim/blenderbim/bim/module/project/operator.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ifcopenshell.api
55
import bpy
66
from blenderbim.bim.ifc import IfcStore
7+
from blenderbim.bim import import_ifc
78

89

910
class CreateProject(bpy.types.Operator):
@@ -220,3 +221,37 @@ class SaveLibraryFile(bpy.types.Operator):
220221
def execute(self, context):
221222
IfcStore.library_file.write(IfcStore.library_path)
222223
return {"FINISHED"}
224+
225+
226+
class AppendLibraryElement(bpy.types.Operator):
227+
bl_idname = "bim.append_library_element"
228+
bl_label = "Append Library Element"
229+
definition: bpy.props.IntProperty()
230+
231+
def execute(self, context):
232+
element = ifcopenshell.api.run(
233+
"project.append_asset",
234+
IfcStore.get_file(),
235+
element=IfcStore.library_file.by_id(self.definition),
236+
)
237+
self.import_type_from_ifc(element)
238+
return {"FINISHED"}
239+
240+
def import_type_from_ifc(self, element):
241+
self.file = IfcStore.get_file()
242+
logger = logging.getLogger("ImportIFC")
243+
ifc_import_settings = import_ifc.IfcImportSettings.factory(bpy.context, IfcStore.path, logger)
244+
245+
type_collection = bpy.data.collections.get("Types")
246+
if not type_collection:
247+
type_collection = bpy.data.collections.new("Types")
248+
for collection in bpy.data.collections:
249+
if "IfcProject/" in collection.name:
250+
collection.children.link(type_collection)
251+
break
252+
253+
ifc_importer = import_ifc.IfcImporter(ifc_import_settings)
254+
ifc_importer.file = self.file
255+
ifc_importer.type_collection = type_collection
256+
ifc_importer.create_type_product(element)
257+
ifc_importer.place_objects_in_spatial_tree()

src/blenderbim/blenderbim/bim/module/project/ui.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def draw_create_project_ui(self, context):
7171
class BIM_PT_project_library(Panel):
7272
bl_label = "IFC Project Library"
7373
bl_idname = "BIM_PT_project_library"
74+
bl_options = {"DEFAULT_CLOSED"}
7475
bl_space_type = "PROPERTIES"
7576
bl_region_type = "WINDOW"
7677
bl_context = "scene"
@@ -117,14 +118,16 @@ def draw_item(self, context, layout, data, item, icon, active_data, active_propn
117118
op.element_name = item.name
118119
row.label(text=item.name)
119120
if (
120-
not item.ifc_definition_id
121-
or IfcStore.library_file.schema == "IFC2X3"
122-
or not IfcStore.library_file.by_type("IfcProjectLibrary")
121+
item.ifc_definition_id
122+
and IfcStore.library_file.schema != "IFC2X3"
123+
and IfcStore.library_file.by_type("IfcProjectLibrary")
123124
):
124-
return
125-
if item.is_declared:
126-
op = row.operator("bim.unassign_library_declaration", text="", icon="KEYFRAME_HLT", emboss=False)
127-
op.definition = item.ifc_definition_id
128-
else:
129-
op = row.operator("bim.assign_library_declaration", text="", icon="KEYFRAME", emboss=False)
125+
if item.is_declared:
126+
op = row.operator("bim.unassign_library_declaration", text="", icon="KEYFRAME_HLT", emboss=False)
127+
op.definition = item.ifc_definition_id
128+
else:
129+
op = row.operator("bim.assign_library_declaration", text="", icon="KEYFRAME", emboss=False)
130+
op.definition = item.ifc_definition_id
131+
if item.ifc_definition_id:
132+
op = row.operator("bim.append_library_element", text="", icon="APPEND_BLEND")
130133
op.definition = item.ifc_definition_id

src/ifcopenshell-python/ifcopenshell/api/cost/add_cost_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ def execute(self):
2323
)
2424
elif self.settings["cost_item"]:
2525
ifcopenshell.api.run(
26-
"nest.assign_object", self.file, object=cost_item, relating_object=self.settings["cost_item"]
26+
"nest.assign_object", self.file, related_object=cost_item, relating_object=self.settings["cost_item"]
2727
)
2828
return cost_item

0 commit comments

Comments
 (0)