bimdown-cli 0.1.5 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +709 -72
- package/dist/index.js.map +1 -1
- package/dist/spec/csv-schema/architecture/ceiling.yaml +9 -0
- package/dist/spec/csv-schema/architecture/column.yaml +8 -0
- package/dist/spec/csv-schema/architecture/curtain_wall.yaml +31 -0
- package/dist/spec/csv-schema/architecture/door.yaml +35 -0
- package/dist/spec/csv-schema/architecture/opening.yaml +36 -0
- package/dist/spec/csv-schema/architecture/railing.yaml +7 -0
- package/dist/spec/csv-schema/architecture/ramp.yaml +7 -0
- package/dist/spec/csv-schema/architecture/roof.yaml +22 -0
- package/dist/spec/csv-schema/architecture/room_separator.yaml +5 -0
- package/dist/spec/csv-schema/architecture/slab.yaml +15 -0
- package/dist/spec/csv-schema/architecture/space.yaml +17 -0
- package/dist/spec/csv-schema/architecture/stair.yaml +11 -0
- package/dist/spec/csv-schema/architecture/wall.yaml +11 -0
- package/dist/spec/csv-schema/architecture/window.yaml +13 -0
- package/dist/spec/csv-schema/base/element.yaml +60 -0
- package/dist/spec/csv-schema/base/hosted_element.yaml +15 -0
- package/dist/spec/csv-schema/base/line_element.yaml +25 -0
- package/dist/spec/csv-schema/base/materialized.yaml +22 -0
- package/dist/spec/csv-schema/base/mep_connected_segment.yaml +17 -0
- package/dist/spec/csv-schema/base/mep_system.yaml +7 -0
- package/dist/spec/csv-schema/base/point_element.yaml +17 -0
- package/dist/spec/csv-schema/base/polygon_element.yaml +14 -0
- package/dist/spec/csv-schema/base/section_profile.yaml +16 -0
- package/dist/spec/csv-schema/base/spatial_line_element.yaml +13 -0
- package/dist/spec/csv-schema/base/structural_section_profile.yaml +21 -0
- package/dist/spec/csv-schema/base/vertical_span.yaml +17 -0
- package/dist/spec/csv-schema/grid.yaml +26 -0
- package/dist/spec/csv-schema/level.yaml +17 -0
- package/dist/spec/csv-schema/mep/cable_tray.yaml +8 -0
- package/dist/spec/csv-schema/mep/conduit.yaml +8 -0
- package/dist/spec/csv-schema/mep/duct.yaml +8 -0
- package/dist/spec/csv-schema/mep/equipment.yaml +22 -0
- package/dist/spec/csv-schema/mep/mep_node.yaml +6 -0
- package/dist/spec/csv-schema/mep/pipe.yaml +8 -0
- package/dist/spec/csv-schema/mep/terminal.yaml +19 -0
- package/dist/spec/csv-schema/mesh.yaml +40 -0
- package/dist/spec/csv-schema/structure/beam.yaml +7 -0
- package/dist/spec/csv-schema/structure/brace.yaml +7 -0
- package/dist/spec/csv-schema/structure/foundation.yaml +22 -0
- package/dist/spec/csv-schema/structure/structure_column.yaml +8 -0
- package/dist/spec/csv-schema/structure/structure_slab.yaml +14 -0
- package/dist/spec/csv-schema/structure/structure_wall.yaml +9 -0
- package/dist/spec/duckdb-strategy.md +93 -0
- package/dist/spec/llm-classification.md +453 -0
- package/dist/spec/migration-guide.md +248 -0
- package/dist/spec/project_metadata.schema.yaml +21 -0
- package/dist/spec/readme.md +247 -0
- package/dist/spec/svg-schema/readme.md +165 -0
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: foundation
|
|
2
|
+
bases:
|
|
3
|
+
- element
|
|
4
|
+
- materialized
|
|
5
|
+
description: >
|
|
6
|
+
Unified foundation type. Geometry form is determined by the SVG element:
|
|
7
|
+
- <rect>/<circle> (point-based): isolated/pad footing
|
|
8
|
+
- <path> (line-based): strip/continuous footing
|
|
9
|
+
- <polygon> (polygon-based): raft/mat foundation
|
|
10
|
+
Computed geometry fields are hydrated from SVG at query time.
|
|
11
|
+
|
|
12
|
+
fields:
|
|
13
|
+
- name: thickness
|
|
14
|
+
type: float
|
|
15
|
+
|
|
16
|
+
- name: width
|
|
17
|
+
type: float
|
|
18
|
+
description: Width of strip foundation or pad dimension
|
|
19
|
+
|
|
20
|
+
- name: length
|
|
21
|
+
type: float
|
|
22
|
+
description: Length of pad foundation
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# BimDown: DuckDB & CLI Integration Strategy
|
|
2
|
+
|
|
3
|
+
The core challenge of **Agentic AI** in BIM environments:
|
|
4
|
+
1. **Generative tasks** need tiny, bounded contexts (a single floor's walls) to avoid hallucination.
|
|
5
|
+
2. **Analytical tasks** require cross-building relational views with geometry calculations.
|
|
6
|
+
|
|
7
|
+
BimDown bridges this via a **CLI tool** wrapping **DuckDB**.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 1. Hydration Phase (Import)
|
|
12
|
+
|
|
13
|
+
When the Agent needs global context (e.g. executing SQL), the CLI initializes an in-memory DuckDB database.
|
|
14
|
+
|
|
15
|
+
### A. Union of Partitions
|
|
16
|
+
|
|
17
|
+
Merges level-specific and global CSV files into single logical tables:
|
|
18
|
+
```sql
|
|
19
|
+
CREATE TABLE wall AS SELECT * FROM '*/wall.csv';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### B. Geometry Injection (Computed Fields)
|
|
23
|
+
|
|
24
|
+
The CLI parses SVG files and injects geometry as virtual columns:
|
|
25
|
+
- `<path>` → `start_x`, `start_y`, `end_x`, `end_y`, `length`
|
|
26
|
+
- `<rect>`/`<circle>` → `x`, `y`, `size_x`, `size_y`, `rotation`
|
|
27
|
+
- `<polygon>` → `points` (serialized), `area`
|
|
28
|
+
|
|
29
|
+
Elements without SVG (door, window, space, grid) have their geometry fields directly from CSV — no injection needed.
|
|
30
|
+
|
|
31
|
+
**Result**: The LLM gets rich tables with spatial data for SQL queries, despite physical CSVs holding only semantic columns.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 2. Execution Phase (Standard SQL)
|
|
36
|
+
|
|
37
|
+
The LLM is abstracted from the file system:
|
|
38
|
+
|
|
39
|
+
```sql
|
|
40
|
+
-- Change all sliding doors wider than 0.9m on 1F to swing doors
|
|
41
|
+
UPDATE door SET operation = 'single_swing'
|
|
42
|
+
WHERE width > 0.9 AND level_id = 'lv-1' AND operation = 'sliding';
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## 3. Sync-Out Phase (Dehydration & Auto-Healing)
|
|
48
|
+
|
|
49
|
+
### A. Stripping Computed Fields
|
|
50
|
+
|
|
51
|
+
When writing back to physical CSVs, the CLI strips `computed: true` columns. The CSV remains purely semantic.
|
|
52
|
+
|
|
53
|
+
### B. Auto-Healing
|
|
54
|
+
|
|
55
|
+
LLMs are mathematically imprecise. When an AI draws a `<path>` for a door opening that measures 0.887m instead of the CSV-declared 0.9m width:
|
|
56
|
+
|
|
57
|
+
1. The CSV `width = 0.9` is the **source of truth**.
|
|
58
|
+
2. The CLI detects the SVG/CSV mismatch.
|
|
59
|
+
3. Takes the SVG midpoint as the placement intent.
|
|
60
|
+
4. Redraws the SVG symmetrically around that midpoint to match 0.9m.
|
|
61
|
+
|
|
62
|
+
This creates a resilient **twin-engine**:
|
|
63
|
+
- **CSV** enforces semantic truth (widths, materials, types).
|
|
64
|
+
- **SVG** enforces spatial intent (where things are placed).
|
|
65
|
+
- **CLI** keeps them in sync.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## 4. Resolve-Topology (MEP Connectivity)
|
|
70
|
+
|
|
71
|
+
AI designs MEP networks by placing duct/pipe segments with endpoint coordinates. The CLI provides a `resolve-topology` command that:
|
|
72
|
+
|
|
73
|
+
1. Collects all MEP segment endpoints and equipment/terminal positions.
|
|
74
|
+
2. Detects coincident coordinates (within tolerance).
|
|
75
|
+
3. Auto-generates `mep_node` entries at pure junction points (where no equipment/terminal exists).
|
|
76
|
+
4. Back-fills `start_node_id` and `end_node_id` on each duct/pipe/cable_tray/conduit.
|
|
77
|
+
|
|
78
|
+
After resolution, DuckDB graph queries work naturally:
|
|
79
|
+
```sql
|
|
80
|
+
-- Find all ducts connected to equipment eq-1
|
|
81
|
+
SELECT d.* FROM duct d
|
|
82
|
+
WHERE d.start_node_id = 'eq-1' OR d.end_node_id = 'eq-1';
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 5. Partitioning (Sync-Out)
|
|
88
|
+
|
|
89
|
+
When writing back to the filesystem, the CLI re-partitions by level:
|
|
90
|
+
|
|
91
|
+
- Elements with `vertical_span` where `top_level_id` is **more than one level above** base → `global/`
|
|
92
|
+
- All other elements → `{level_id}/`
|
|
93
|
+
- `level.csv`, `grid.csv` → always `global/`
|
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
# LLM-Based Classification for BimDown Export
|
|
2
|
+
|
|
3
|
+
## Problem
|
|
4
|
+
|
|
5
|
+
When exporting from Revit to BimDown CSV, raw Revit strings (material names, family names, parameter names) must be mapped to BimDown's spec-defined enum values and field names. Hardcoded string matching rules cannot cover all cases because:
|
|
6
|
+
|
|
7
|
+
- Material names vary by language, vendor, and project conventions
|
|
8
|
+
- Family parameter names are user-defined (e.g. `b`/`h` vs `Width`/`Depth` vs `宽`/`高`)
|
|
9
|
+
- Equipment and terminal types can only be inferred from family/type names
|
|
10
|
+
- Door operation types depend on family naming conventions
|
|
11
|
+
|
|
12
|
+
## Design
|
|
13
|
+
|
|
14
|
+
### Classification Dimensions
|
|
15
|
+
|
|
16
|
+
| Dimension | Granularity | Source (Revit) | Target (BimDown) | Current Implementation |
|
|
17
|
+
|-----------|-------------|----------------|-------------------|----------------------|
|
|
18
|
+
| Material name | per Material | `Material.Name` | `material` enum | `MaterializedExtractor` hardcoded `contains()` |
|
|
19
|
+
| Family param names | per Family | Parameter `.Name` | BimDown fields (`size_x`, `width`, `height`...) | `ParameterUtils.FindDoubleParameterByNames` hardcoded list |
|
|
20
|
+
| Equipment type | per Family | Family name / type name | `equipment_type` enum | null (not implemented) |
|
|
21
|
+
| Terminal type | per Family | Family name / type name | `terminal_type` enum | null (not implemented) |
|
|
22
|
+
| Door operation | per Family | Family name / param values | `operation` enum | `GetDoorOperation` hardcoded rules |
|
|
23
|
+
| Roof type | per Element | Slope value | `roof_type` enum | Simple slope check (0=flat, else gable) |
|
|
24
|
+
|
|
25
|
+
Key insight: **Material** is a shared Revit entity (not per-family), so it needs its own lookup table. All other classifications are per-family since elements of the same family share parameter structure.
|
|
26
|
+
|
|
27
|
+
### Two-Phase Workflow
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
Phase 1: Export (Revit process)
|
|
31
|
+
├─ Load _classification_cache.json (if exists)
|
|
32
|
+
├─ Export all tables
|
|
33
|
+
│ ├─ For each field: check cache → fallback to hardcoded rules
|
|
34
|
+
│ └─ Collect unknown materials and unmapped families into hints
|
|
35
|
+
├─ Write CSVs, SVGs, metadata
|
|
36
|
+
└─ Write _classification_hints.json (unknowns for LLM)
|
|
37
|
+
|
|
38
|
+
Phase 2: Classify (CLI, outside Revit)
|
|
39
|
+
├─ Read _classification_hints.json
|
|
40
|
+
├─ Build LLM prompt (batch all unknowns in one call)
|
|
41
|
+
├─ Call LLM API → structured JSON response
|
|
42
|
+
├─ Merge results into _classification_cache.json
|
|
43
|
+
└─ User re-exports from Revit (cache now covers previously unknown families)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### File Locations
|
|
47
|
+
|
|
48
|
+
Both files live in the **project root directory** (alongside `project_metadata.json`):
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
{project}/
|
|
52
|
+
├── project_metadata.json
|
|
53
|
+
├── _classification_cache.json # Persistent cache (committed to repo)
|
|
54
|
+
├── _classification_hints.json # Temporary (generated on export, consumed by classify)
|
|
55
|
+
├── global/
|
|
56
|
+
├── lv-1/
|
|
57
|
+
└── ...
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Cache File: `_classification_cache.json`
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"materials": {
|
|
67
|
+
"C30 Concrete": "concrete",
|
|
68
|
+
"Generic - Interior Partition": "gypsum",
|
|
69
|
+
"Aluminum Frame": "aluminum",
|
|
70
|
+
"Custom Facade Panel": "composite"
|
|
71
|
+
},
|
|
72
|
+
"families": {
|
|
73
|
+
"column::Concrete-Rectangular Column": {
|
|
74
|
+
"params": {
|
|
75
|
+
"size_x": "b",
|
|
76
|
+
"size_y": "h"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"door::Single-Flush": {
|
|
80
|
+
"params": {
|
|
81
|
+
"width": "Width",
|
|
82
|
+
"height": "Height"
|
|
83
|
+
},
|
|
84
|
+
"enums": {
|
|
85
|
+
"operation": "single_swing"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"equipment::M_AHU - Horizontal": {
|
|
89
|
+
"enums": {
|
|
90
|
+
"equipment_type": "ahu"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"terminal::M_Supply Diffuser - Perforated": {
|
|
94
|
+
"enums": {
|
|
95
|
+
"terminal_type": "supply_air_diffuser"
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"window::Fixed Window": {
|
|
99
|
+
"params": {
|
|
100
|
+
"width": "Width",
|
|
101
|
+
"height": "Height"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- `materials`: Revit material name (string) → BimDown enum value
|
|
109
|
+
- `families`: key is `{bimdown_category}::{revit_family_name}`
|
|
110
|
+
- `params`: BimDown field name → Revit parameter name (for numeric/string value extraction)
|
|
111
|
+
- `enums`: BimDown field name → BimDown enum value (classification from family identity)
|
|
112
|
+
|
|
113
|
+
### Cache Behavior
|
|
114
|
+
|
|
115
|
+
- Cache is **additive** — new entries are merged, existing entries are never overwritten automatically
|
|
116
|
+
- Users can **manually edit** the cache to correct LLM mistakes; manual edits survive re-classification
|
|
117
|
+
- Cache is **project-scoped** — different projects may have different family libraries
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Hints File: `_classification_hints.json`
|
|
122
|
+
|
|
123
|
+
Generated during export for entries not found in cache:
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"materials": [
|
|
128
|
+
{
|
|
129
|
+
"name": "Unknown Custom Material",
|
|
130
|
+
"used_by_categories": ["wall", "slab"]
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"name": "Precast - Exposed Aggregate",
|
|
134
|
+
"used_by_categories": ["structure_wall"]
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"families": [
|
|
138
|
+
{
|
|
139
|
+
"key": "column::Custom Column Family",
|
|
140
|
+
"category": "column",
|
|
141
|
+
"family_name": "Custom Column Family",
|
|
142
|
+
"type_names": ["300x500", "400x600"],
|
|
143
|
+
"instance_params": [
|
|
144
|
+
{ "name": "b", "type": "double", "sample": "0.3" },
|
|
145
|
+
{ "name": "h", "type": "double", "sample": "0.5" },
|
|
146
|
+
{ "name": "Cover", "type": "double", "sample": "0.04" }
|
|
147
|
+
],
|
|
148
|
+
"type_params": [
|
|
149
|
+
{ "name": "Concrete Grade", "type": "string", "sample": "C30" },
|
|
150
|
+
{ "name": "Mark", "type": "string", "sample": "C1" }
|
|
151
|
+
],
|
|
152
|
+
"fields_needed": {
|
|
153
|
+
"params": [
|
|
154
|
+
{ "field": "size_x", "description": "Cross-section width (meters)" },
|
|
155
|
+
{ "field": "size_y", "description": "Cross-section depth (meters)" }
|
|
156
|
+
],
|
|
157
|
+
"enums": []
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"key": "equipment::Custom Chiller Unit",
|
|
162
|
+
"category": "equipment",
|
|
163
|
+
"family_name": "Custom Chiller Unit",
|
|
164
|
+
"type_names": ["100kW", "200kW"],
|
|
165
|
+
"instance_params": [
|
|
166
|
+
{ "name": "Capacity", "type": "double", "sample": "100" }
|
|
167
|
+
],
|
|
168
|
+
"type_params": [],
|
|
169
|
+
"fields_needed": {
|
|
170
|
+
"params": [],
|
|
171
|
+
"enums": [
|
|
172
|
+
{
|
|
173
|
+
"field": "equipment_type",
|
|
174
|
+
"values": ["ahu", "fcu", "chiller", "boiler", "cooling_tower", "fan", "pump", "transformer", "panelboard", "generator", "water_heater", "tank", "other"]
|
|
175
|
+
}
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
"element_families": {
|
|
181
|
+
"c-1": "column::Custom Column Family",
|
|
182
|
+
"c-2": "column::Custom Column Family",
|
|
183
|
+
"eq-1": "equipment::Custom Chiller Unit"
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
- `element_families` maps element IDs to their family key, enabling CLI to know which cache entry applies to which CSV row (for potential future CLI-side backfill)
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Fields Needing Classification Per Category
|
|
193
|
+
|
|
194
|
+
| BimDown Category | param mapping fields | enum classification fields |
|
|
195
|
+
|-----------------|---------------------|--------------------------|
|
|
196
|
+
| wall | thickness* | material |
|
|
197
|
+
| structure_wall | thickness* | material |
|
|
198
|
+
| column | size_x, size_y | material |
|
|
199
|
+
| structure_column | size_x, size_y | material |
|
|
200
|
+
| slab | thickness | material |
|
|
201
|
+
| structure_slab | thickness | material |
|
|
202
|
+
| door | width, height | material, operation |
|
|
203
|
+
| window | width, height | material |
|
|
204
|
+
| beam | size_x, size_y | material |
|
|
205
|
+
| brace | size_x, size_y | material |
|
|
206
|
+
| foundation (isolated) | length, width, thickness | material |
|
|
207
|
+
| curtain_wall | — | material, panel_material |
|
|
208
|
+
| stair | width | — |
|
|
209
|
+
| equipment | — | equipment_type |
|
|
210
|
+
| terminal | — | terminal_type |
|
|
211
|
+
| roof | thickness | material, roof_type** |
|
|
212
|
+
|
|
213
|
+
*Wall thickness comes from `Wall.Width` API, not a named parameter — no mapping needed.
|
|
214
|
+
**Roof type may need LLM for complex roof forms (hip, mansard, shed).
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Revit Plugin Changes
|
|
219
|
+
|
|
220
|
+
### New: `ClassificationCache.cs`
|
|
221
|
+
|
|
222
|
+
```csharp
|
|
223
|
+
class ClassificationCache
|
|
224
|
+
{
|
|
225
|
+
Dictionary<string, string> Materials; // raw_name → enum
|
|
226
|
+
Dictionary<string, FamilyMapping> Families; // "category::family" → mapping
|
|
227
|
+
|
|
228
|
+
static ClassificationCache Load(string projectDir);
|
|
229
|
+
void Save(string projectDir);
|
|
230
|
+
|
|
231
|
+
string? GetMaterial(string rawMaterialName);
|
|
232
|
+
string? GetParamName(string category, string familyName, string field);
|
|
233
|
+
string? GetEnumValue(string category, string familyName, string field);
|
|
234
|
+
bool HasFamily(string category, string familyName);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
record FamilyMapping(
|
|
238
|
+
Dictionary<string, string>? Params, // bimdown_field → revit_param_name
|
|
239
|
+
Dictionary<string, string>? Enums); // bimdown_field → enum_value
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### New: `ClassificationCollector.cs`
|
|
243
|
+
|
|
244
|
+
```csharp
|
|
245
|
+
class ClassificationCollector
|
|
246
|
+
{
|
|
247
|
+
Dictionary<string, HashSet<string>> UnknownMaterials; // name → categories
|
|
248
|
+
Dictionary<string, FamilyHint> UnknownFamilies; // key → hint
|
|
249
|
+
Dictionary<string, string> ElementFamilies; // element_id → family_key
|
|
250
|
+
|
|
251
|
+
void RecordMaterial(string rawName, string category);
|
|
252
|
+
void RecordFamily(Element element, string category, string[] paramFields, string[] enumFields);
|
|
253
|
+
void RecordElementFamily(string elementId, string category, string familyName);
|
|
254
|
+
void WriteHints(string projectDir);
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Modified Extractors
|
|
259
|
+
|
|
260
|
+
Each extractor that does string mapping receives `ClassificationCache` and `ClassificationCollector` via a shared context object:
|
|
261
|
+
|
|
262
|
+
```csharp
|
|
263
|
+
class ExportContext
|
|
264
|
+
{
|
|
265
|
+
public ClassificationCache Cache { get; }
|
|
266
|
+
public ClassificationCollector Collector { get; }
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Extractors are modified to:
|
|
271
|
+
1. Check cache first
|
|
272
|
+
2. Fall back to existing hardcoded rules
|
|
273
|
+
3. Record unknowns to collector
|
|
274
|
+
|
|
275
|
+
Example — `MaterializedExtractor`:
|
|
276
|
+
|
|
277
|
+
```csharp
|
|
278
|
+
public Dictionary<string, string?> Extract(Element element)
|
|
279
|
+
{
|
|
280
|
+
var rawName = GetRawMaterialName(element);
|
|
281
|
+
if (rawName is null) return new() { ["material"] = "composite" };
|
|
282
|
+
|
|
283
|
+
// 1. Cache hit
|
|
284
|
+
var cached = _context.Cache.GetMaterial(rawName);
|
|
285
|
+
if (cached is not null) return new() { ["material"] = cached };
|
|
286
|
+
|
|
287
|
+
// 2. Hardcoded fallback
|
|
288
|
+
var fallback = MapToEnum(rawName);
|
|
289
|
+
|
|
290
|
+
// 3. Record if fallback is uncertain
|
|
291
|
+
if (fallback == "composite")
|
|
292
|
+
_context.Collector.RecordMaterial(rawName, _currentCategory);
|
|
293
|
+
|
|
294
|
+
return new() { ["material"] = fallback };
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Example — `SectionProfileExtractor` (for columns):
|
|
299
|
+
|
|
300
|
+
```csharp
|
|
301
|
+
public Dictionary<string, string?> Extract(Element element)
|
|
302
|
+
{
|
|
303
|
+
var familyName = GetFamilyName(element);
|
|
304
|
+
var category = _currentCategory;
|
|
305
|
+
|
|
306
|
+
// 1. Try cache for param name mapping
|
|
307
|
+
var sizeXParam = _context.Cache.GetParamName(category, familyName, "size_x");
|
|
308
|
+
var sizeYParam = _context.Cache.GetParamName(category, familyName, "size_y");
|
|
309
|
+
|
|
310
|
+
double? sizeX = null, sizeY = null;
|
|
311
|
+
if (sizeXParam is not null)
|
|
312
|
+
sizeX = element.LookupParameter(sizeXParam)?.AsDouble();
|
|
313
|
+
if (sizeYParam is not null)
|
|
314
|
+
sizeY = element.LookupParameter(sizeYParam)?.AsDouble();
|
|
315
|
+
|
|
316
|
+
// 2. Fallback to existing search
|
|
317
|
+
sizeX ??= FindDoubleParameterByNames(element, "width", "w", "b", "宽");
|
|
318
|
+
sizeY ??= FindDoubleParameterByNames(element, "height", "depth", "h", "d", "高", "深");
|
|
319
|
+
|
|
320
|
+
// 3. Record unknown family if either is still null
|
|
321
|
+
if ((sizeX is null || sizeY is null) && !_context.Cache.HasFamily(category, familyName))
|
|
322
|
+
_context.Collector.RecordFamily(element, category, ["size_x", "size_y"], []);
|
|
323
|
+
|
|
324
|
+
return new()
|
|
325
|
+
{
|
|
326
|
+
["shape"] = DetectShape(element),
|
|
327
|
+
["size_x"] = sizeX is { } x ? FormatDouble(Length(x)) : null,
|
|
328
|
+
["size_y"] = sizeY is { } y ? FormatDouble(Length(y)) : null,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Modified ExportCommand
|
|
334
|
+
|
|
335
|
+
```csharp
|
|
336
|
+
public Result Execute(...)
|
|
337
|
+
{
|
|
338
|
+
// ... setup ...
|
|
339
|
+
|
|
340
|
+
// Load classification cache
|
|
341
|
+
var cache = ClassificationCache.Load(outputDir);
|
|
342
|
+
var collector = new ClassificationCollector();
|
|
343
|
+
var exportContext = new ExportContext(cache, collector);
|
|
344
|
+
|
|
345
|
+
// Pass extractors the context (via constructor or thread-static)
|
|
346
|
+
// ... export all tables ...
|
|
347
|
+
|
|
348
|
+
// Write outputs
|
|
349
|
+
WriteCsvs(...);
|
|
350
|
+
WriteSvgs(...);
|
|
351
|
+
WriteMetadata(...);
|
|
352
|
+
collector.WriteHints(outputDir); // Write _classification_hints.json
|
|
353
|
+
|
|
354
|
+
// ... write IDs to model ...
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
---
|
|
359
|
+
|
|
360
|
+
## CLI Changes
|
|
361
|
+
|
|
362
|
+
### New Command: `bimdown classify <project-dir>`
|
|
363
|
+
|
|
364
|
+
```
|
|
365
|
+
1. Read _classification_hints.json
|
|
366
|
+
- If not found or empty → print "Nothing to classify" and exit
|
|
367
|
+
|
|
368
|
+
2. Read _classification_cache.json (if exists)
|
|
369
|
+
- Filter out hints that are already in cache
|
|
370
|
+
|
|
371
|
+
3. Build LLM prompt
|
|
372
|
+
- Group materials and families into a single structured prompt
|
|
373
|
+
- Include enum value options for each field
|
|
374
|
+
- Request JSON output
|
|
375
|
+
|
|
376
|
+
4. Call LLM API (Anthropic Claude)
|
|
377
|
+
- Single API call for all unknowns
|
|
378
|
+
- Parse structured JSON response
|
|
379
|
+
|
|
380
|
+
5. Merge results into _classification_cache.json
|
|
381
|
+
- Only add new entries, never overwrite existing (user edits are preserved)
|
|
382
|
+
|
|
383
|
+
6. Delete _classification_hints.json
|
|
384
|
+
|
|
385
|
+
7. Print summary: "Classified X materials, Y families. Re-export from Revit to apply."
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### LLM Prompt Template
|
|
389
|
+
|
|
390
|
+
```
|
|
391
|
+
You are a BIM data classification assistant. Given Revit model metadata, map raw
|
|
392
|
+
strings to BimDown schema values.
|
|
393
|
+
|
|
394
|
+
## Task 1: Material Classification
|
|
395
|
+
|
|
396
|
+
Map each Revit material name to ONE of these values:
|
|
397
|
+
concrete, steel, wood, clt, glass, aluminum, brick, stone, gypsum, insulation,
|
|
398
|
+
copper, pvc, ceramic, fiber_cement, composite
|
|
399
|
+
|
|
400
|
+
Materials to classify:
|
|
401
|
+
| Material Name | Used By |
|
|
402
|
+
|---|---|
|
|
403
|
+
| Generic - Interior Partition | wall, slab |
|
|
404
|
+
| Precast - Exposed Aggregate | structure_wall |
|
|
405
|
+
|
|
406
|
+
## Task 2: Family Parameter Mapping
|
|
407
|
+
|
|
408
|
+
For each Revit family, determine which parameter corresponds to each BimDown field.
|
|
409
|
+
|
|
410
|
+
### Family: "Custom Column" (category: column)
|
|
411
|
+
Instance params: b(double, sample=0.3), h(double, sample=0.5), Cover(double, sample=0.04)
|
|
412
|
+
Type params: Grade(string, sample="C30"), Mark(string, sample="C1")
|
|
413
|
+
|
|
414
|
+
Map these fields (choose the best matching parameter name, or null if none):
|
|
415
|
+
- size_x: cross-section width in meters
|
|
416
|
+
- size_y: cross-section depth in meters
|
|
417
|
+
|
|
418
|
+
### Family: "M_AHU - Horizontal" (category: equipment)
|
|
419
|
+
Instance params: Air Flow(double, sample=2.5), Width(double, sample=0.5)
|
|
420
|
+
|
|
421
|
+
Classify (choose one value):
|
|
422
|
+
- equipment_type: [ahu, fcu, chiller, boiler, cooling_tower, fan, pump,
|
|
423
|
+
transformer, panelboard, generator, water_heater, tank, other]
|
|
424
|
+
|
|
425
|
+
## Response Format
|
|
426
|
+
|
|
427
|
+
Return JSON only:
|
|
428
|
+
{
|
|
429
|
+
"materials": {
|
|
430
|
+
"Generic - Interior Partition": "gypsum",
|
|
431
|
+
"Precast - Exposed Aggregate": "concrete"
|
|
432
|
+
},
|
|
433
|
+
"families": {
|
|
434
|
+
"column::Custom Column": {
|
|
435
|
+
"params": { "size_x": "b", "size_y": "h" },
|
|
436
|
+
"enums": {}
|
|
437
|
+
},
|
|
438
|
+
"equipment::M_AHU - Horizontal": {
|
|
439
|
+
"params": {},
|
|
440
|
+
"enums": { "equipment_type": "ahu" }
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
---
|
|
447
|
+
|
|
448
|
+
## Open Questions
|
|
449
|
+
|
|
450
|
+
1. **LLM Backend**: Call Anthropic API directly from CLI, or route through a custom backend service?
|
|
451
|
+
2. **Re-export vs CLI backfill**: After `classify`, user re-exports from Revit (simpler, cache is applied). Or CLI rewrites CSVs directly (no re-export needed, but requires `element_families` mapping)?
|
|
452
|
+
3. **Batch size**: If a project has hundreds of unknown families, should we split into multiple LLM calls?
|
|
453
|
+
4. **Confidence**: Should the LLM response include confidence? Should low-confidence results be flagged for user review?
|