Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ rvtio sheets project.rvt sheets.json

The catalog has the sheet number, name, issue date, by-lines and scale, the viewports of each sheet and the elements each sheet owns, plus the text and whole-number project/shared parameters of each sheet (`--params`, `--csv`, `--where NAME=VALUE` with `!=`/`~` and `*`/`?` wildcards). Page size, view placement, the displayed view and 2D content are not decoded; every limit is reported in the catalog itself. See [sheets and viewports](docs/sheets.md).

Print the plan of a level to PDF — walls with their stored width, column footprints and grids, on the smallest paper that holds the drawing at the scale:
Print the plan of a level to PDF or SVG — walls with their stored width, column footprints and grids, on the smallest paper that holds the drawing at the scale:

```sh
rvtio print project.rvt plan.pdf --level "Уровень 1" --scale 100
rvtio print project.rvt plan.svg --level "Уровень 1" --scale 100
```

`--list-levels` prints the levels that can be printed. A sheet prints from its decoded linework (page border, title block frame, rules) on the paper it spans:
Expand Down
12 changes: 9 additions & 3 deletions docs/printing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Printing a plan

`rvtio print` renders the plan of one level of a Revit project to a PDF page without Revit. This is the first view
`rvtio print` renders the plan of one level of a Revit project to a PDF page or an SVG drawing without Revit. This is the first view
renderer of the sheet printing work described in [issue #18](https://github.com/IOExtend/RvtIO/issues/18): it draws the
model geometry the reader decodes, not the linework Revit generates for a view. It is a working drawing of the level,
not yet a printed sheet.
Expand All @@ -14,6 +14,9 @@ rvtio print project.rvt --list-levels
# the plan of one level at 1:100 on the smallest paper that holds it
rvtio print project.rvt plan.pdf --level 355 --scale 100

# the same level plan exported as SVG (1 user unit = 1 mm, UTF-8 XML with scale and sheet metadata)
rvtio print project.rvt plan.svg --level 355 --scale 100

# a fixed paper size
rvtio print project.rvt plan.pdf --level "Уровень 1" --scale 200 --paper A3
```
Expand Down Expand Up @@ -44,8 +47,11 @@ of its level. A plan view is a `DBViewPlan` of the
file whose name matches a printable level (or whose stored elevation equals the level's); a section or an elevation is
left out until its renderer exists.

The library API is `RvtIO.Print.PlanPrinter`: `Levels(document)` returns the printable levels, and
`Render(document, levelId, scale, options)` returns a `PdfDocument` with one page.
The library API is `RvtIO.Print.PlanPrinter`: `Levels(document)` returns the printable levels,
`Render(document, levelId, scale, options)` returns a `PdfDocument` with one page, and
`RenderSvg(document, levelId, scale, options)` returns the level plan as SVG text.
`WriteSvg(document, output, levelId, scale, options)` writes the same SVG as UTF-8 and leaves the destination stream open.
PDF and SVG share geometry, scale, and paper layout. Use finite, non-negative margins that leave a positive area on the paper.

## Images

Expand Down
2 changes: 1 addition & 1 deletion docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ See [sheets and viewports](sheets.md) for what is decoded, what the limits are a

| Type | Use |
|---|---|
| `PlanPrinter` | `Levels(document)` lists the levels a plan can be printed for; `Render(document, levelId, scale, options)` returns a `PdfDocument` with the plan of one level: walls with their stored width, column footprints, clipped grids. |
| `PlanPrinter` | `Levels(document)` lists the printable levels. `Render(document, levelId, scale, options)` returns a `PdfDocument` with the plan of one level, including walls with their stored width, column footprints, and clipped grids. `RenderSvg(document, ...)` returns the same level plan as SVG text. `WriteSvg(document, output, ...)` writes it as UTF-8 to a stream. |
| `PlanPrintOptions` | `PaperSize` (null picks the smallest paper that holds the drawing), `MarginMillimetres`, `FallbackWallWidthMillimetres`, `DrawFrame`. |
| `PlanLevel`, `PlanView` | A printable level (id, name, elevation) and a printable plan view (id, name, level, scale). |
| `ViewPrinter` | `Render(document, viewIds, options)` prints views into one PDF document, one page per view: a plan, an elevation or a section (`PlanPrinter.Views`, `ElevationPrinter.Views`), a 3D view (an isometric massing page) and a rendering (its image page). `OtherViews(document)` lists the 3D views and the renderings. |
Expand Down
75 changes: 56 additions & 19 deletions src/RvtIO.Cli/PrintCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
namespace RvtIO.Cli;

/// <summary>
/// <c>rvtio print &lt;file.rvt&gt; &lt;out.pdf&gt; [--level &lt;id|name&gt;] [--view &lt;id|name&gt;] [--sheet &lt;id|number&gt;] [--where FILTER] [--scale &lt;n&gt;]
/// [--paper A4|A3|A2|A1|A0]</c>: renders the plan of one level, or one or more plan views at their own scales, to a PDF
/// <c>rvtio print &lt;file.rvt&gt; &lt;out.pdf|out.svg&gt; [--level &lt;id|name&gt;] [--view &lt;id|name&gt;] [--sheet &lt;id|number&gt;] [--where FILTER] [--scale &lt;n&gt;]
/// [--paper A4|A3|A2|A1|A0]</c>: renders the plan of one level to PDF or SVG (<c>.svg</c>), or one or more plan views or sheets at their own scales to PDF
/// (see <see cref="PlanPrinter"/>). <c>--list-levels</c> and <c>--list-views</c> print what can be printed instead.
/// <c>--where NAME=VALUE</c> (also <c>!=</c> and <c>~</c> for contains, <c>*</c> and <c>?</c> wildcards, repeatable) keeps
/// only the sheets whose parameters match; it needs <c>--sheet</c>, <c>--all-sheets</c> or <c>--list-sheets</c>.
Expand Down Expand Up @@ -89,7 +89,10 @@ internal static int Run(string[] args, TextWriter output, TextWriter error)
if (whereFilters.Count > 0 && sheetTexts.Count == 0 && !allSheets && !listSheets)
return Usage(error, "--where selects sheets; it needs --sheet, --all-sheets or --list-sheets.");
bool listing = listLevels || listViews || listSheets;
if (!listing && outputPath == null) return Usage(error, "print requires the output PDF path.");
if (!listing && outputPath == null) return Usage(error, "print requires the output PDF path (or .svg for a level plan).");
bool svgOutput = outputPath != null && outputPath.EndsWith(".svg", StringComparison.OrdinalIgnoreCase);
if (svgOutput && (allSheets || allViews || sheetTexts.Count > 0 || viewTexts.Count > 0 || whereFilters.Count > 0))
return Usage(error, "SVG output supports level plan rendering only (--level, --scale, --paper); use a .pdf path for views and sheets.");
// File identity also catches when a link in the output path points to the input model.
if (outputPath != null && FileIdentity.SameFile(outputPath, file))
{
Expand Down Expand Up @@ -194,6 +197,39 @@ IReadOnlyList<ComposedSheet> ListedComposed() =>

try
{
if (svgOutput)
{
if (levels.Count == 0)
{
error.WriteLine("No level with a wall or column was found; nothing to print.");
return RvtExitCodes.DecodeError;
}
int? levelId = ResolveLevelId(levelText, levels);
if (levelText != null && levelId == null)
{
error.WriteLine($"No printable level is named or numbered '{levelText}'. --list-levels shows them.");
return RvtExitCodes.Usage;
}

PdfPageSize svgPaper;
double effectiveScale;
string temporarySvg = outputPath + "." + Guid.NewGuid().ToString("N") + ".tmp";
try
{
using (var fs = File.Create(temporarySvg))
PlanPrinter.WriteSvg(document, fs, levelId, scale, new PlanPrintOptions { PaperSize = paper },
out svgPaper, out effectiveScale);
File.Move(temporarySvg, outputPath!, overwrite: true);
}
catch
{
if (File.Exists(temporarySvg)) File.Delete(temporarySvg);
throw;
}
error.WriteLine($"[print] 1 page(s), first {svgPaper.WidthMillimetres:0} x {svgPaper.HeightMillimetres:0} mm (1:{effectiveScale:0}) -> {outputPath}");
return RvtExitCodes.Success;
}

PdfDocument pdf;
if (allSheets)
{
Expand Down Expand Up @@ -277,22 +313,11 @@ IReadOnlyList<ComposedSheet> ListedComposed() =>
error.WriteLine("No level with a wall or column was found; nothing to print.");
return RvtExitCodes.DecodeError;
}
int? levelId = null;
if (levelText != null)
int? levelId = ResolveLevelId(levelText, levels);
if (levelText != null && levelId == null)
{
foreach (PlanLevel level in levels)
{
if (int.TryParse(levelText, NumberStyles.None, CultureInfo.InvariantCulture, out int id) && id == level.LevelId)
levelId = level.LevelId;
else if (string.Equals(level.Name, levelText, StringComparison.OrdinalIgnoreCase))
levelId = level.LevelId;
if (levelId != null) break;
}
if (levelId == null)
{
error.WriteLine($"No printable level is named or numbered '{levelText}'. --list-levels shows them.");
return RvtExitCodes.Usage;
}
error.WriteLine($"No printable level is named or numbered '{levelText}'. --list-levels shows them.");
return RvtExitCodes.Usage;
}
pdf = PlanPrinter.Render(document, levelId, scale, new PlanPrintOptions { PaperSize = paper });
}
Expand Down Expand Up @@ -406,10 +431,22 @@ internal static ExplicitSheetSelection SelectExplicitSheets(
return new ExplicitSheetSelection(sheetIds, composedIds, null);
}

private static int? ResolveLevelId(string? levelText, IReadOnlyList<PlanLevel> levels)
{
if (levelText == null) return null;
bool byId = int.TryParse(levelText, NumberStyles.None, CultureInfo.InvariantCulture, out int id);
foreach (PlanLevel level in levels)
{
if ((byId && id == level.LevelId) || string.Equals(level.Name, levelText, StringComparison.OrdinalIgnoreCase))
return level.LevelId;
}
return null;
}

private static int Usage(TextWriter error, string problem)
{
error.WriteLine(problem);
error.WriteLine("Usage: rvtio print <file.rvt> <out.pdf> [--level <id|name>] [--view <id|name>] [--sheet <id|number>] "
error.WriteLine("Usage: rvtio print <file.rvt> <out.pdf|out.svg> [--level <id|name>] [--view <id|name>] [--sheet <id|number>] "
+ "[--where FILTER] [--all-views] [--all-sheets] [--scale <n>] [--paper A4|A3|A2|A1|A0] "
+ "[--list-levels] [--list-views] [--list-sheets]");
return RvtExitCodes.Usage;
Expand Down
4 changes: 2 additions & 2 deletions src/RvtIO.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ Report options (read the file and print or write a report instead of exporting):
--list-category <categoryId> <out.csv> list the elements of one category
sheets <file.rvt|file.rfa> [output.json] [--r22-layout] [--where FILTER] [--params] [--csv] [--json]
write the sheet catalog (sheets, viewports, parameters, limits not decoded) as JSON
print <file.rvt> <out.pdf> [--level <id|name>] [--view <id|name>] [--sheet <id|number>] [--where FILTER] [--scale <n>]
print <file.rvt> <out.pdf|out.svg> [--level <id|name>] [--view <id|name>] [--sheet <id|number>] [--where FILTER] [--scale <n>]
[--all-views] [--all-sheets] [--paper A4|A3|A2|A1|A0]
[--list-levels] [--list-views] [--list-sheets]
render the plan of one level, one or more views (plans and elevations) or all of
render the plan of one level (to PDF or SVG), one or more views (plans and elevations) or all of
them, or one or more sheets, to PDF

Developer options (measurement and comparison dumps, not a stable interface):
Expand Down
Loading
Loading