Repository navigation
fix(viewer): make Export IFC and Export plan SVG work in the browser - #288
Merged
Merged
Conversation
Both buttons failed on every click since they shipped (7d54d3f, 2026-04-20); confirmed on the deployed site. Two stacked causes: - The exports call wasm on the main thread, which never initialised its own instance (only the worker does), so every call died with "Cannot read properties of undefined (reading '__wbindgen_add_to_stack_pointer')". main.ts now initialises one main-thread instance on first export and retries on the next click if initialisation fails. - Behind that, the STEP writer stamped its header with SystemTime::now(), which panics on wasm32-unknown-unknown ("time not implemented on this platform"). The wasm build now reads Date.now() through the bindings. Every wasm binding now installs the panic hook, not only the byte-opening ones, so a main-thread panic reports its message instead of a bare "unreachable" (that is how the second cause was found). The viewer suite downloads both exports and checks for an ISO-10303-21 header and an <svg> root.
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_b5d8b180-2c08-4a1f-952a-e9c75865cf78) |
17 tasks done
DrunkOnJava
added a commit
that referenced
this pull request
Sep 22, 2026
…viewer and Python (#289) ## Summary Element and room schedules as CSV — the spreadsheet people actually want from a Revit file they cannot open — from a new `rvt-schedule` CLI, the viewer's Schedule panel, and Python's `RevitFile.schedule_csv()`, all backed by one `rvt::ifc::schedule_csv` module. ## Motivation The decoded model (walls, doors with their host wall, windows, columns, slabs, rooms with names and numbers on Revit 2024 projects) was only reachable as IFC, glTF, SVG or raw JSON. A schedule in Excel / Sheets / LibreOffice is the most common ask from people without Revit. ## Changes - `src/ifc/schedule_csv.rs` (new): `elements_csv` (Revit ElementId, IFC type, predefined type, name, level + elevation, material, x/y/z, rotation, width/depth/height of the emitted rectangular body, host ElementId for doors/windows, `body_source`, `profile_resolved`) and `rooms_csv` (ElementId, number, name, level + elevation, body source). Feet or metres; optional UTF-8 BOM for Excel on Windows; RFC 4180 with CRLF; storey order then numeric ElementId. - Only decoded values are written; unknowns are empty cells. - **No room area**: room bodies are record bounding boxes (`ProfileResolved = false`), and a box area is not a room area. - **CSV-injection guard**: cells come from an untrusted file, so a text cell starting with `=`, `+`, `-`, `@`, tab or CR is prefixed with `'` (OWASP). The older `scene_graph::Schedule::to_csv` gets the same guard. - `src/bin/rvt_schedule.rs` (new, 19th CLI): `rvt-schedule model.rvt` → `model.elements.csv`; `--schedule rooms`; `--metric`; `--excel`; `-o -` for stdout; refuses to overwrite the input; tells you to run `rvt-inspect` when nothing decoded. - Wasm `scheduleCsv(model, kind, metric, excel)`; viewer **Download element schedule (CSV)** / **Download room schedule (CSV)** under Schedule, enabled only when the model has elements / rooms, built on the main-thread wasm instance from #288. - Python `RevitFile.schedule_csv(kind="elements", metric=False, excel=False)` + stubs. - Docs: README (CLI list "Nineteen", examples, What-works row), user guide "Get A Schedule Into Excel", python.md, viewer-api.md, status.md, support-matrix `csv-schedules` row (`partial`: coverage is exactly the decode coverage), CHANGELOG. ## Testing - [x] `tools/check-local.sh` with both corpora: fmt, clippy -D warnings, rustdoc -D warnings, 1,276 tests passed, 0 failed - [x] `cargo +1.85.0 check --profile ci --all-targets` (MSRV) - [x] Unit tests (7): decoded values vs blanks, host ElementId, storey + natural ElementId order, metric conversion + column names, formula neutralisation and RFC 4180 quoting of an untrusted room name (`=HYPERLINK("x")`, `Lobby, East`), BOM toggle, compact numbers - [x] `tests/rvt_schedule_cli.rs`: tier-1 shape (17 columns, no ragged rows, stdout + BOM + metric header), one named error for a missing input, and on `2024_Core_Interior.rvt` (corpus-gated) 970 element rows — 360 IFCWALL, 132 IFCDOOR (all hosted), 6 IFCWINDOW, 256 IFCCOLUMN, 116 IFCSPACE — plus 116 room rows with number and name - [x] Python: 64 passed (2 new: header shapes, unknown kind raises `ValueError`) - [x] Viewer: `wasm-pack build`, typecheck, build, network-import audit PASS, Playwright 14 passed — the Einhoven test downloads the element schedule and checks the BOM + header - [x] `binary_inventory` (README "Nineteen CLIs ship"), `cli_ergonomics` (help examples now include `rvt-schedule`) ## Audit-honesty checklist - [x] README / docs reflect the current state after this PR — the support-matrix row is `partial` and says rows equal decode coverage - [x] If a limitation was resolved, the "Known limitations" / "What works today" section in the relevant docs is updated - [x] New limitation documented: no room area (bounding-box bodies); schedules are only as complete as the file's decode (typed rows on Revit 2024 projects with element records) - [x] Commit messages describe WHAT changed and WHY - [x] No emojis in code, docs, or commit messages - [x] No private paths, personal email addresses, or internal jargon in committed files - [x] N/A: not a reverse-engineering finding ## Legal and contribution hygiene - [x] I agree this work is licensable under Apache-2.0 (see `CONTRIBUTING.md`) - [x] This PR contains no Autodesk proprietary source, decompiled internals, or NDA'd SDK content (see `CLEANROOM.md`) - [x] Test fixtures: tier-1 synthetics; the magnetar project (MIT) is corpus-gated, not committed ## Breaking changes None. `scene_graph::Schedule::to_csv` now prefixes formula-like cells with `'`. ## Screenshots or output samples ``` $ rvt-schedule 2024_Core_Interior.rvt rvt-schedule: wrote 970 element rows to 2024_Core_Interior.elements.csv $ head -3 2024_Core_Interior.elements.csv revit_element_id,ifc_type,predefined_type,name,level,level_elevation_ft,material,x_ft,y_ft,z_ft,rotation_deg,width_ft,depth_ft,height_ft,host_revit_element_id,body_source,profile_resolved 21975,IFCSLAB,FLOOR,BuildingPad-21975,Basement 2,-40,,93.5,69.5,-43,,,,1.5,,partition_element_record_bbox,true 22771,IFCWALL,NOTDEFINED,Wall-22771,Basement 2,-40,,92.75,113.25,-40,,145.5,1.5,40,,partition_element_record_join_trimmed,false $ rvt-schedule 2024_Core_Interior.rvt --schedule rooms --metric rvt-schedule: wrote 116 room rows to 2024_Core_Interior.rooms.csv ``` ## Related issues Refs #90 (room boundary polygons — why the room schedule has no area). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Mostly additive export surfaces and defensive CSV escaping; the only behavior change is formula-neutralization in existing `Schedule::to_csv` output. > > **Overview** > Adds **spreadsheet schedules** for decoded building elements and rooms, shared across a new **`rvt-schedule` CLI**, the browser viewer, and **`RevitFile.schedule_csv()`**, all built on **`rvt::ifc::schedule_csv`**. > > The element CSV includes Revit ElementId, IFC type, level, material, placement, rectangular body dimensions, door/window host ids, and geometry provenance; the room CSV has number, name, and level (no area). Options cover **feet vs metres**, optional **UTF-8 BOM for Excel**, and **stdout** output. Rows reflect **decode coverage only** (empty cells for unknowns). > > **Security:** text cells that could trigger spreadsheet formula injection are prefixed with `'`, including in the older **`scene_graph::Schedule::to_csv`**. > > Docs, support matrix, and tests cover CLI shape, Python API, wasm **`scheduleCsv`**, and Playwright download checks. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 8bb1b56. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
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.
Summary
The browser viewer's Export IFC and Export plan SVG buttons have failed on every click since they shipped (commit 7d54d3f, 2026-04-20). This fixes both, and the viewer suite now proves each one downloads real output.
Motivation
Confirmed on the deployed site (https://drunkonjava.github.io/rvt-rs/) before touching anything, with a throwaway Playwright probe that opens the Einhoven demo card and clicks both buttons:
The README advertises one-click Export glTF / IFC / plan SVG; only glTF (built in the worker) worked. No test clicked the other two.
Changes
Two stacked causes:
init()on its own instance. The export handlersawait import('../pkg/rvt.js')on the main thread and callmodelToIfcStep/renderPlanSvgon an uninitialised--target webmodule.viewer/src/main.tsgainsmainThreadWasm(): one memoised main-thread initialisation, not cached on failure so the next click retries.SystemTime::now()panics onwasm32-unknown-unknown. With (1) fixed, Export IFC panicked:time not implemented on this platform.ifc::step_writer::unix_seconds()reads the JavaScript host clock (Date.now(), a new wasm-bindgen import) on wasm32 with thewasmfeature and keepsSystemTimeeverywhere else.Also: every wasm binding now installs the panic hook, not only the byte-opening ones. Without that the second cause surfaced as a bare
RuntimeError: unreachable— the hook is per instance, and the main thread's instance never ran a byte-opening binding.docs/viewer-api.mddocuments the per-thread initialisation and the hook; CHANGELOG entry under Fixed.Testing
viewer/tests/viewer-regression.spec.ts: the demo-gallery MVP test now clicks Export IFC and Export plan SVG, waits for each download, and asserts anISO-10303-21;header / an<svgroot and no "failed" status. Red before the fix (timeout, statusIFC export failed: …__wbindgen_add_to_stack_pointer; after fixing only the init:IFC export failed: unreachable), green after.wasm-pack build,npm run typecheck,npm run build, Playwright 14 passed; wasm network-import audit PASScargo clippy --workspace --all-targets --all-features -- -D warnings(the host-clock helper is wasm32-only),cargo fmt --checkAudit-honesty checklist
Legal and contribution hygiene
CONTRIBUTING.md)CLEANROOM.md)Breaking changes
None.
Screenshots or output samples
Deployed site before the fix: see Motivation. After the fix, locally: both downloads complete,
statusreadsexported <file>.ifc/exported <file>.svg.Related issues
None
Note
Medium Risk
Changes wasm export initialization and wall-clock sourcing for IFC headers in the browser build; native IFC output path is unchanged but wasm surface area grows across many bindings.
Overview
Restores the browser viewer’s Export IFC and Export plan SVG actions, which had been broken since ship due to two stacked wasm issues.
The main thread now lazy-initialises its own wasm module (
mainThreadWasm()inviewer/src/main.ts) before callingmodelToIfcStep/renderPlanSvg, because parsing’s worker instance does not satisfy--target webcalls from the UI thread. IFC STEP header timestamps no longer useSystemTime::now()onwasm32(which panics); they readDate.now()via a newhost_now_millis()helper. Every wasm binding installs the panic hook on first use so main-thread export failures log a readable message instead ofRuntimeError: unreachable.Docs (
viewer-api.md) and CHANGELOG record per-realm init and panic behaviour; Playwright now clicks both export buttons and asserts real STEP/SVG downloads.Reviewed by Cursor Bugbot for commit 547bdb8. Configure here.