Skip to content

Commit

Permalink
Regenerate missing sheets #4462
Browse files Browse the repository at this point in the history
BlenderBIM will regenerate missing SVG drawings from the IFC on demand,
now it attempts to regenerate missing SVG sheets too. ie. you can open a
bare IFC file with configured drawings and sheets and continue working.

Only drawings are recognised, spreadsheet and other SVG refs are not
regenerated, all drawings are placed at the 30,30 pixel location.
  • Loading branch information
brunopostle committed Apr 20, 2024
1 parent 60a70f5 commit 3ef823d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/blenderbim/blenderbim/bim/module/drawing/operator.py
Expand Up @@ -2373,6 +2373,7 @@ def _execute(self, context):
if not filepath.is_file():
sheet_name = f"{sheet_prop.identification} - {sheet_prop.name}"
sheets_not_found.append(f'"{sheet_name}" - {document_uri}')
core.regenerate_sheet(tool.Drawing, sheet)

if sheets_not_found:
self.report({"ERROR"}, "Some sheets svg files are missing:\n" + "\n".join(sheets_not_found))
Expand Down
2 changes: 1 addition & 1 deletion src/blenderbim/blenderbim/bim/module/drawing/svgwriter.py
Expand Up @@ -93,7 +93,7 @@ def draw_underlay(self, image):

def setup_drawing_resource_paths(self, element):
pset = ifcopenshell.util.element.get_pset(element, "EPset_Drawing")
for resource in ("Stylesheet", "Markers", "Symbols", "Patterns"):
for resource in ("Stylesheet", "Markers", "Symbols", "Patterns", "ShadingStyles"):
resource_path = pset.get(resource)
if not resource_path:
self.resource_paths[resource] = None
Expand Down
8 changes: 8 additions & 0 deletions src/blenderbim/blenderbim/core/drawing.py
Expand Up @@ -16,6 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.

from pathlib import Path


def enable_editing_text(drawing, obj=None):
drawing.enable_editing_text(obj)
Expand Down Expand Up @@ -89,6 +91,12 @@ def add_sheet(ifc, drawing, titleblock=None):
drawing.import_sheets()


def regenerate_sheet(drawing, sheet=None):
titleblock_uri = drawing.get_document_uri(sheet, "TITLEBLOCK")
drawing.create_svg_sheet(sheet, drawing.sanitise_filename(Path(titleblock_uri).stem))
drawing.add_drawings(sheet)


def open_sheet(drawing, sheet=None):
drawing.open_layout_svg(drawing.get_document_uri(sheet, "LAYOUT"))

Expand Down
15 changes: 15 additions & 0 deletions src/blenderbim/blenderbim/tool/drawing.py
Expand Up @@ -247,6 +247,21 @@ def create_svg_sheet(cls, document, titleblock):
sheet_builder.create(uri, titleblock)
return uri

@classmethod
def add_drawings(cls, sheet):
sheet_builder = sheeter.SheetBuilder()
sheet_builder.data_dir = bpy.context.scene.BIMProperties.data_dir
sheet_reference = None
drawing_names = []
for reference in cls.get_document_references(sheet):
if reference.Description == "LAYOUT":
sheet_reference = reference
elif reference.Description == "DRAWING":
drawing_names.append(Path(reference.Location).stem)
for annotation in [e for e in tool.Ifc.get().by_type("IfcAnnotation") if e.ObjectType == "DRAWING"]:
if annotation.Name in drawing_names:
sheet_builder.add_drawing(sheet_reference, annotation, sheet)

@classmethod
def delete_collection(cls, collection):
bpy.data.collections.remove(collection, do_unlink=True)
Expand Down

0 comments on commit 3ef823d

Please sign in to comment.