Skip to content

Commit

Permalink
bim.create_drawing to sync only once if printing multiple drawings
Browse files Browse the repository at this point in the history
Turned out syncing process takes too much time on large projects, so we can speed up the printing process by syncing just once. Also exposed option not to sync to operator's properties to allow debugging failing elements.

A bit related to #4500
  • Loading branch information
Andrej730 committed Apr 4, 2024
1 parent 57fe408 commit 797e2e4
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/blenderbim/blenderbim/bim/module/drawing/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ class CreateDrawing(bpy.types.Operator):
+ "SHIFT+CLICK to print all selected drawings"
)
print_all: bpy.props.BoolProperty(name="Print All", default=False, options={"SKIP_SAVE"})
sync: bpy.props.BoolProperty(
name="Sync Before Creating Drawing",
description="Could save some time if you're sure IFC and current Blender session are already in sync",
default=True,
)

@classmethod
def poll(cls, context):
Expand All @@ -220,7 +225,8 @@ def execute(self, context):
else:
drawings_to_print = [self.props.active_drawing_id]

for drawing_id in drawings_to_print:
for drawing_i, drawing_id in enumerate(drawings_to_print):
self.drawing_index = drawing_i
if self.print_all:
bpy.ops.bim.activate_drawing(drawing=drawing_id, camera_view_point=False)

Expand Down Expand Up @@ -485,13 +491,17 @@ def generate_linework(self, context: bpy.types.Context) -> Union[str, None]:
if os.path.isfile(svg_path) and self.props.should_use_linework_cache:
return svg_path

with profile("sync"):
# All very hackish whilst prototyping
exporter = blenderbim.bim.export_ifc.IfcExporter(None)
exporter.file = tool.Ifc.get()
invalidated_elements = exporter.sync_all_objects()
invalidated_elements += exporter.sync_edited_objects()
invalidated_guids = [e.GlobalId for e in invalidated_elements if hasattr(e, "GlobalId")]
# in case of printing multiple drawings we need to sync just once
if self.sync and self.drawing_index == 0:
with profile("sync"):
# All very hackish whilst prototyping
exporter = blenderbim.bim.export_ifc.IfcExporter(None)
exporter.file = tool.Ifc.get()
invalidated_elements = exporter.sync_all_objects()
invalidated_elements += exporter.sync_edited_objects()
invalidated_guids = [e.GlobalId for e in invalidated_elements if hasattr(e, "GlobalId")]
cache = IfcStore.get_cache()
[cache.remove(guid) for guid in invalidated_guids]

# If we have already calculated it in the SVG in the past, don't recalculate
edited_guids = set()
Expand Down Expand Up @@ -525,8 +535,6 @@ def generate_linework(self, context: bpy.types.Context) -> Union[str, None]:
drawing_elements = tool.Drawing.get_drawing_elements(self.camera_element)

self.setup_serialiser(ifc, target_view)
cache = IfcStore.get_cache()
[cache.remove(guid) for guid in invalidated_guids]
tree = ifcopenshell.geom.tree()
tree.enable_face_styles(True)

Expand Down

0 comments on commit 797e2e4

Please sign in to comment.