docs: document drawing stylesheets and the override pattern - #9358
Draft
BIMvoice wants to merge 1 commit into
Draft
docs: document drawing stylesheets and the override pattern#9358BIMvoice wants to merge 1 commit into
BIMvoice wants to merge 1 commit into
Conversation
…files Bonsai's drawing CSS (default.css) and its comma-separated, cascading stylesheet setting were undocumented. Add a guide covering where the setting lives (project pset vs add-on preferences, and why it only affects new drawings), the override-instead-of-edit pattern, a class reference generated from default.css and cross-checked against what svgwriter.py/SvgSerializer.cpp actually emit, unit conversions, worked recipes and troubleshooting. Add three short starter override files (heavy lineweight, fine lineweight, presentation greys) referenced from the guide.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bonsai styles its SVG drawings with CSS, and the system is genuinely capable.
default.csscovers cut versus projection, edge classification, named line weights, every annotation predefined type, text sizes and material hatches.But there is currently no documentation for any of it. Searching
src/bonsai/docs/for "stylesheet" returns nothing. So a BIM coordinator who wants heavier walls in plan has to discover the file exists, find it, learn CSS, and guess that the selector is.cut.This adds a guide written for that person rather than for a developer.
The thing most worth documenting
svgwriter.py'sadd_stylesheet()splits the path on commas and appends each file in order:So normal CSS cascade applies and later files win. Nobody needs to edit
default.css. They set the path todefault.css, my-office.cssand write three lines of their own. That reduces "learn CSS and edit a 103 line file" to "add two lines", and as far as I can tell it has never been written down anywhere.Verified by running the real cascade logic against two files and confirming in rendered output that the second file's rule wins on a shared selector while untouched properties still inherit from the first.
Also documented, because it costs people an afternoon
core/drawing.py:335bakes the resolved path onto each drawing'sEPset_Drawingat creation time:Changing the project pset or the add-on preference therefore affects future drawings only. An existing drawing keeps the path it was created with and has to be edited directly. That is reasonable behaviour but surprising, and it is the first thing someone hits when they change the setting and nothing happens.
What is in the guide
Where the setting lives, tracing both the
BBIM_Documentation/StylesheetPathpset onIfcProjectand the add-on preference fallback. The override pattern, front and centre. A class reference generated fromdefault.cssand cross-checked against what the code actually emits. A units section, since stroke widths are millimetres while font sizes are px with mm equivalents in comments. Six worked recipes for common requests. Troubleshooting, including that a mistyped class fails silently.Plus three short starter override files, ten to twenty lines each, override-only rather than copies of the default.
Findings along the way, reported rather than fixed
Nothing here is changed by this PR. Flagging them because they turned up while cross-checking the reference against the source.
.material-blanknever matches. The code emitsmaterial-null(bim/module/drawing/operator.py:1460) anddefault.csshas no rule for that class, so elements without a material fall through unstyled. Confirmed by grep: zero occurrences ofmaterial-nullin the CSS.Material class names are case sensitive.
canonicalise_class_name(tool/drawing.py:170) only strips non-alphanumerics, so a material named "Concrete" yieldsmaterial-Concreteand silently misses thematerial-concretehatch rule. This is documented in the troubleshooting section as something to watch for, since it is a real trap regardless of whether the code changes.Five selectors are dead.
.PredefinedType-STUD,WOOD,STEEL,CONCRETEandPLASTERBOARDare not emitted anywhere in the Python or the C++.sample.csslooks orphaned. It is referenced nowhere and uses a stale vocabulary (.hidden,.solid,.leader) that does not match current selectors.One thing I checked and want to correct in advance, in case it looks like a bug:
.PredefinedType-RADIUSpoints at#fall-marker-endand.PredefinedType-FALLat#radius-marker-end, which reads as a swap. It has no visible effect, because both markers inmarkers.svghave byte-identical geometry (M 0 3.5 L 0 10.5 L 10 7). Untidy, not broken, so I have left it alone.Verification and its limits
The cascade was verified by executing the real
add_stylesheet()logic and rendering the result, not by reading the code. The RST parses cleanly under docutils.Not verified: end to end drawing generation inside Blender. The cascade behaviour was proven directly, but nobody has produced a real drawing with an override file through the full Bonsai pipeline. Worth someone doing before this is relied on.
Produced with AI assistance.