Portability: Blender/ODA discovery via env > PATH > macOS default

The two hardcoded macOS paths in code become last-resort defaults:
- build_showcase_variants: env BLENDER > shutil.which("blender") > app bundle
- cad_dxf_report: env ODA_CONVERTER > shutil.which("ODAFileConverter") > app
  bundle (env override existed already; PATH lookup is new)
Docs annotate the macOS example paths with the discovery order.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-04 15:05:32 +08:00
parent 23cf3af678
commit b871a2f8bd
4 changed files with 20 additions and 4 deletions

View File

@@ -66,7 +66,7 @@ The pipeline is designed so a first pass either succeeds or STOPS at a loud gate
1. Prepare the CAD folder.
- Work from a folder under the current workspace when possible. On macOS, avoid direct reads from `Downloads` if TCC blocks access; ask the user to move/copy the CAD folder into the workspace.
- Preserve the original CAD folder. Put converted/intermediate files in `work/`.
- If DWG files are present, prefer `libredwg` `dwg2dxf` for batch conversion. Use ODA/QCAD/FreeCAD only as fallback — EXCEPT for drawings containing `3DSOLID`/ACIS entities: libredwg silently drops ACIS data (R2013+ stores it in the ACDSDATA section), so 3D-solid DWGs must go through ODA File Converter (`/Applications/ODAFileConverter.app/Contents/MacOS/ODAFileConverter <abs_in_dir> <abs_out_dir> ACAD2004 DXF 0 1 "*.dwg"`). ODA reports bad arguments via GUI dialogs, not stderr: both directories must exist as absolute paths, and a silent exit-0 with no output means a dialog is blocking on screen.
- If DWG files are present, prefer `libredwg` `dwg2dxf` for batch conversion. Use ODA/QCAD/FreeCAD only as fallback — EXCEPT for drawings containing `3DSOLID`/ACIS entities: libredwg silently drops ACIS data (R2013+ stores it in the ACDSDATA section), so 3D-solid DWGs must go through ODA File Converter (`/Applications/ODAFileConverter.app/Contents/MacOS/ODAFileConverter <abs_in_dir> <abs_out_dir> ACAD2004 DXF 0 1 "*.dwg"` — macOS path shown; discovery order everywhere is env `ODA_CONVERTER` > `ODAFileConverter` on PATH > that macOS default). ODA reports bad arguments via GUI dialogs, not stderr: both directories must exist as absolute paths, and a silent exit-0 with no output means a dialog is blocking on screen.
- No native converter available (Linux sandbox, no ODA/libredwg)? Use the WASM fallback: `npm install @mlightcad/libredwg-web`, then `node scripts/dwg_dump_json.mjs in.dwg dump.json --module-dir <node_modules>` and `python3 scripts/dwgjson_to_dxf.py --json dump.json --out work/dxf_raw/file.dxf`. This carries LINE/PLINE/ARC/CIRCLE/ELLIPSE/SPLINE/TEXT/INSERT + full block definitions (enough for the extraction pipeline), but drops HATCH/DIMENSION/ATTRIB — do not use it to judge hatch-only column fills or attribute-held axis numbers.
- Multi-discipline sets (建筑/结构/给排水/电气/暖通 subfolders): model from 建筑 (architecture) only by default; pull 结构 later just for columns/beams if the showcase needs structure. Never feed all disciplines into one extraction pass.
@@ -99,7 +99,7 @@ The pipeline is designed so a first pass either succeeds or STOPS at a loud gate
- Review the Markdown audit and SVG overlays. Iterate config if important geometry remains unclassified or hidden in high-risk entity types.
5. Generate Blender/GLB.
- Use Blender CLI:
- Use Blender CLI (macOS app-bundle path shown; on Linux/other, `blender` from PATH works — `build_showcase_variants.py` discovers it via env `BLENDER` > PATH > the macOS default):
`/Applications/Blender.app/Contents/MacOS/Blender -b --python <skill>/scripts/build_blender_showcase.py -- --spec work/building_spec.json --out-dir outputs/<project> --name <project>`
- Use Blender MCP only after the CLI artifact exists, for inspection, scene tuning, or interactive refinement.

View File

@@ -236,12 +236,16 @@ Expected outputs:
- `<project>.png`
- `model_metadata.json`
If Blender CLI fails, verify the path. On this machine, the app path has been:
If Blender CLI fails, verify the path. The macOS app-bundle path is:
```text
/Applications/Blender.app/Contents/MacOS/Blender
```
On Linux/other platforms use `blender` from PATH; scripts discover the
executable via env `BLENDER` > PATH > the macOS default, and ODA File
Converter via env `ODA_CONVERTER` > PATH > its macOS default.
## 8. Web Showcase
For a quick single-model preview, run:

View File

@@ -8,6 +8,8 @@ Blender to produce GLBs. Its manifest is consumed by write_web_showcase.py.
from __future__ import annotations
import argparse
import shutil
import os
import copy
import json
import subprocess
@@ -38,6 +40,13 @@ VARIANTS = [
def default_blender() -> str:
"""Blender executable: env BLENDER > PATH > macOS app-bundle default."""
override = os.environ.get("BLENDER")
if override:
return override
found = shutil.which("blender")
if found:
return found
return "/Applications/Blender.app/Contents/MacOS/Blender"

View File

@@ -86,10 +86,13 @@ def run_dwg2dxf(source: Path, dest: Path) -> dict:
def oda_converter() -> str | None:
"""ODA File Converter path (env ODA_CONVERTER overrides the macOS default)."""
"""ODA File Converter: env ODA_CONVERTER > PATH > macOS app-bundle default."""
override = os.environ.get("ODA_CONVERTER")
if override:
return override if Path(override).exists() else None
found = shutil.which("ODAFileConverter")
if found:
return found
default = Path("/Applications/ODAFileConverter.app/Contents/MacOS/ODAFileConverter")
return str(default) if default.exists() else None