Skip to content

Feat: Nest ifcAnnotation inside drawing group (Fix #7903)#7922

Draft
dipayansardar73-decode wants to merge 1 commit intoIfcOpenShell:v0.8.0from
dipayansardar73-decode:fix-7903-nest-annotations-v2
Draft

Feat: Nest ifcAnnotation inside drawing group (Fix #7903)#7922
dipayansardar73-decode wants to merge 1 commit intoIfcOpenShell:v0.8.0from
dipayansardar73-decode:fix-7903-nest-annotations-v2

Conversation

@dipayansardar73-decode
Copy link
Copy Markdown

Fixes #7903.

This PR replaces the existing string-based SVG combination logic in combine_svgs with an XML-aware approach using lxml.etree.

Changes

  • Parses the linework.svg to identify the main drawing group (e.g., <g class="section target-view-SECTIONVIEW scale-50">).
    • Injects the elements from annotation.svg directly inside this group.
    • This ensures that all ifcAnnotation elements (like linework, text, labels, and measures) properly inherit the scale and view-specific CSS classes applied to the root drawing group.

Replaces the string-concatenation SVG merge with an lxml structural merge in combine_svgs. This moves the ifcAnnotation elements inside the main linework drawing group, allowing them to properly inherit CSS styles and scales assigned to the view.
@theoryshaw theoryshaw marked this pull request as draft April 9, 2026 14:40
@theoryshaw
Copy link
Copy Markdown
Member

Got the following error when trying bim.create_drawing,
test file: https://hub.openingdesign.com/OpeningDesign/3_Season_Porch_URGC/src/commit/7f27c30c5d32e821d442a33898132c22babe11e7/Open/Models/Bonsai

Converting this to a 'draft' so it doesn't get pushed to the BleedingEdge build.

Python: Traceback (most recent call last):
  File "C:\Users\Ryan Schultz\AppData\Roaming\Blender Foundation\Blender\4.5\extensions\.local\lib\python3.11\site-packages\bonsai\bim\module\drawing\operator.py", line 397, in execute
    annotation_svg = self.generate_annotation(context)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ryan Schultz\AppData\Roaming\Blender Foundation\Blender\4.5\extensions\.local\lib\python3.11\site-packages\bonsai\bim\module\drawing\operator.py", line 1691, in generate_annotation
    self.svg_writer.create_blank_svg(svg_path).draw_annotations(annotations, precision, decimal_places).save()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ryan Schultz\AppData\Roaming\Blender Foundation\Blender\4.5\extensions\.local\lib\python3.11\site-packages\bonsai\bim\module\drawing\svgwriter.py", line 375, in draw_annotations
    self.draw_section_annotation(obj)
  File "C:\Users\Ryan Schultz\AppData\Roaming\Blender Foundation\Blender\4.5\extensions\.local\lib\python3.11\site-packages\bonsai\bim\module\drawing\svgwriter.py", line 849, in draw_section_annotation
    reference_id, sheet_id = self.get_reference_and_sheet_id_from_annotation(tool.Ifc.get_entity(obj))
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ryan Schultz\AppData\Roaming\Blender Foundation\Blender\4.5\extensions\.local\lib\python3.11\site-packages\bonsai\bim\module\drawing\svgwriter.py", line 898, in get_reference_and_sheet_id_from_annotation
    reference = tool.Drawing.get_drawing_reference(drawing)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ryan Schultz\AppData\Roaming\Blender Foundation\Blender\4.5\extensions\.local\lib\python3.11\site-packages\bonsai\tool\drawing.py", line 2358, in get_drawing_reference
    for rel in drawing.HasAssociations:
               ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'HasAssociations'

Python: Traceback (most recent call last):
  File "C:\Users\Ryan Schultz\AppData\Roaming\Blender Foundation\Blender\4.5\extensions\.local\lib\python3.11\site-packages\bonsai\bim\module\drawing\operator.py", line 400, in execute
    svg_path = self.combine_svgs(context, underlay_svg, linework_svg, annotation_svg)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ryan Schultz\AppData\Roaming\Blender Foundation\Blender\4.5\extensions\.local\lib\python3.11\site-packages\bonsai\bim\module\drawing\operator.py", line 439, in combine_svgs
    root.append(child)
TypeError: append() argument must be xml.etree.ElementTree.Element, not lxml.etree._Element

@theoryshaw
Copy link
Copy Markdown
Member

If you want to test with the same 'assets' see the following...
https://hub.openingdesign.com/OpeningDesign/Bonsai_Tutorials/issues/10#issuecomment-93

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Would be nice to be nest ifcAnnoation like lines/text/etc inside the drawing group.

2 participants