-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrvt_sheet.rs
More file actions
121 lines (110 loc) · 3.11 KB
/
Copy pathrvt_sheet.rs
File metadata and controls
121 lines (110 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! `rvt-sheet` — render a 2D plan view of a Revit file as SVG.
//!
//! Fourth shipping binary in the rvt-rs toolkit. Wraps the VW1-11
//! sheet renderer. Useful for:
//!
//! - embedding a plan in a markdown README or a PDF report
//! - quick visual sanity check after `rvt-write` edits
//! - any workflow that wants a picture without a full 3D viewer
//!
//! Usage:
//!
//! ```bash
//! rvt-sheet --src input.rfa --dst plan.svg
//! rvt-sheet --src input.rfa --dst plan.svg --width 2000 --height 1500
//! rvt-sheet --src input.rfa --dst plan.svg --no-labels --no-background
//! ```
use clap::Parser;
use rvt::RevitFile;
use rvt::ifc::{
Exporter, RvtDocExporter,
sheet::{SheetOptions, render_plan_svg},
};
use std::fs;
use std::path::PathBuf;
use std::process::ExitCode;
#[derive(Parser, Debug)]
#[command(
name = "rvt-sheet",
version,
about = "Render a 2D plan view of a Revit file as SVG"
)]
struct Cli {
/// Source Revit file path.
#[arg(short, long)]
src: PathBuf,
/// Destination .svg file path.
#[arg(short, long)]
dst: PathBuf,
/// Output width in pixels.
#[arg(long, default_value_t = 1200)]
width: u32,
/// Output height in pixels.
#[arg(long, default_value_t = 800)]
height: u32,
/// Interior margin in pixels.
#[arg(long, default_value_t = 40.0)]
margin: f32,
/// Omit element name labels (useful for dense plans).
#[arg(long)]
no_labels: bool,
/// Omit the white background (emit a transparent SVG).
#[arg(long)]
no_background: bool,
/// Print element count + output size on success.
#[arg(long)]
verbose: bool,
}
fn main() -> ExitCode {
let cli = Cli::parse();
match run(&cli) {
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
eprintln!("rvt-sheet: {e}");
ExitCode::from(1)
}
}
}
fn run(cli: &Cli) -> Result<(), String> {
let mut rf =
RevitFile::open(&cli.src).map_err(|e| format!("open {}: {e}", cli.src.display()))?;
let model = RvtDocExporter
.export(&mut rf)
.map_err(|e| format!("export: {e}"))?;
let options = SheetOptions {
width_px: cli.width,
height_px: cli.height,
margin_px: cli.margin,
show_labels: !cli.no_labels,
background: if cli.no_background {
None
} else {
Some("#FFFFFF".into())
},
};
let svg = render_plan_svg(&model, &options);
fs::write(&cli.dst, svg.as_bytes()).map_err(|e| format!("write {}: {e}", cli.dst.display()))?;
if cli.verbose {
let drawn = model
.entities
.iter()
.filter(|e| {
matches!(
e,
rvt::ifc::entities::IfcEntity::BuildingElement {
location_feet: Some(_),
extrusion: Some(_),
..
}
)
})
.count();
println!(
"rvt-sheet: wrote {} bytes ({} drawn elements) to {}",
svg.len(),
drawn,
cli.dst.display()
);
}
Ok(())
}