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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ API between minor releases.

### Added

- CLI and API: `rvtio sheets` lists sheet parameters and filters sheets by them, ported from rvt-prt's `list --params/--where` (Unreleased after 0.1.0). `SheetRecord.Parameters` carries the text and whole-number project/shared parameters of each sheet as display strings (numbers with units stay out until their units are read); Yes/No parameters (`Appears In Sheet List` and project/shared parameters of Yes/No kind, named in `SheetRecord.YesNoParameters`) read as `Yes`/`No`. `rvtio sheets --where NAME=VALUE` (also `!=` and `~` for contains, `*`/`?` wildcards, repeatable, case-insensitive) keeps only matching sheets; on a Yes/No parameter `true/false/1/0` mean `Yes`/`No`, every other field compares literally. A misspelt name or an empty match exits with code 1. `--params` lists each kept sheet's parameters on standard error, `--csv` writes them as CSV, `--json` keeps the default JSON. New API: `SheetFilter.TryParse/Matches`, `SheetCatalog.FromFiltered`. New tests: `SheetFilterTests`.

- CLI and API: `rvtio print <file.rvt> <out.pdf> [--level <id|name>] [--scale <n>] [--paper A4|A3|A2|A1|A0] [--list-levels]` and `RvtIO.Print.PlanPrinter` render the plan of one level to a PDF page from the decoded model: walls as their stored location line drawn two sides of the stored width apart (`WALL_ATTR_WIDTH_PARAM`; 100 mm when neither the wall nor its type stores one), columns as their bounding-box footprint, and grids clipped to the extent of the level. `--list-levels` prints the levels with a drawable wall or column and their stored elevation; without `--level` the level with the most of them is printed. The page is the smallest landscape A4 to A0 that holds the drawing at the scale (a larger drawing is scaled down to fit), with a frame at the margin and the drawing centred. A wall is cut at the openings of its hosted doors and windows: the cut loop of each insert, transformed to the model, leaves its stretch out, the wall is drawn in the pieces between the openings with a jamb at each cut, and a window gets a light line across the opening. The title (level name and scale) is written with an embedded TrueType font found on the machine (Arial, Segoe UI or Tahoma on Windows, DejaVu Sans on Linux, Arial or Helvetica Neue on macOS), which also makes Cyrillic text real, selectable PDF text; without such a font the page is drawn without a title. Sheets print too: `rvtio print --sheet <id|number> [--list-sheets]` renders a sheet page from the location curves of the elements the sheet owns (the page border, the title block frame and rules, tables), on the paper the linework spans (snapped to A4-A0 within 8 mm), with the sheet number and name written in a corner; `RvtIO.Print.SheetPrinter` is the API. A level line ends in the marker the reference export uses: a circle with an arrow head at the right of the drawing, the level name above and its height in millimetres below (Roof Line 6000, Level 2 3000, Ceiling 2700, Level 1 0, Level 1 Living Rm. -550, Foundation -800), each height printed once even though the project holds many level elements at the same height; the drawing reserves a label margin on the right.

A level line of an elevation ends in a level marker: a white circle with the height in metres (+0.000, +3.000, +6.000), as a Revit elevation notes its levels.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ List the sheets and the viewports placed on them:
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. 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).
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:

Expand Down
3 changes: 2 additions & 1 deletion docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ extension and label helpers carry the ids and names stored in the file format.
| Type | Use |
|---|---|
| `SheetCatalog` | `Extract(document)` (or a `RevitFileInfo`) returns the sheets of the file, the viewports placed on them and the limits of this release: `Sheets`, `Viewports` and `Issues`. Nothing is read from the file again. |
| `SheetRecord` | A sheet: `ElementId`, `Number`, `Name`, `IssueDate`, `Scale`, `DrawnBy`, `DesignedBy`, `CheckedBy`, `ApprovedBy`, `ViewportIds` and `OwnedElementIds`. |
| `SheetRecord` | A sheet: `ElementId`, `Number`, `Name`, `IssueDate`, `Scale`, `DrawnBy`, `DesignedBy`, `CheckedBy`, `ApprovedBy`, `ViewportIds`, `OwnedElementIds`, `Parameters` (text/whole-number project/shared params; Yes/No params read as `Yes`/`No`) and `YesNoParameters` (their names). |
| `ViewportRecord` | A placed view: `ElementId`, `SheetId` and `DetailNumber`; `DisplayedViewId` is null until the viewer element is decoded. |
| `SheetIssue`, `SheetIssueKind` | What this release does not decode: page size, view placement, displayed view, view content and crop region. |
| `SheetFilter` | A `--where` filter (`NAME=VALUE`, `!=`, `~`, `*`/`?` wildcards; `true`/`false`/`1`/`0` aliases apply only to Yes/No params); `SheetCatalog.FromFiltered` keeps matching sheets. |

See [sheets and viewports](sheets.md) for what is decoded, what the limits are and why no page coordinate is exposed yet.

Expand Down
20 changes: 20 additions & 0 deletions docs/sheets.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@ With no output path the JSON goes to standard output; diagnostics go to standard
was written, 1 a usage error or an output path that cannot be written, 2 a file that cannot be read, 3 a reader limit
that cut a stream (the codes of [the export report](export-report.md)).

Each `SheetRecord` also carries `Parameters`: the text and whole-number project and shared parameters
of the sheet as display strings (numbers with units stay out until their units are read). A Yes/No parameter
(`Appears In Sheet List` and project/shared parameters of Yes/No kind) reads as `Yes`/`No`; its names are also
listed in `SheetRecord.YesNoParameters`. The port follows rvt-prt's `list --params` (Unreleased after 0.1.0).

```sh
rvtio sheets project.rvt --where "Appears In Sheet List=Yes" --where "Sheet Group=Architectural"
rvtio sheets project.rvt sheets.csv --csv --where "Sheet Name~plan" --where "Sheet Number!=A1*"
rvtio sheets project.rvt --params --where "Drawn By=AB"
```

`--where NAME=VALUE` (also `NAME!=VALUE` and `NAME~TEXT` for contains) keeps only the sheets whose parameters
match, as in rvt-prt. `*` stands for any text and `?` for one character; names and values compare
case-insensitively. On a Yes/No parameter `true`, `false`, `1` and `0` mean the same as `Yes`/`No`;
every other field compares literally, so a sheet number `1` never matches `=true`. A parameter a sheet has no
value for is empty. Repeat a filter for several: all must hold. A name no sheet carries stops with the names there
are (exit code 1), as does a filter nothing matches. `--params` lists each kept sheet's parameters on standard
error, `--csv` writes them as CSV (one row per sheet, one column per parameter), `--json` keeps the default JSON.

## What a sheet is

A sheet is an element that carries the `Sheet Number` or `Sheet Name` parameter. The reader creates those parameters
Expand Down Expand Up @@ -62,6 +81,7 @@ owner, when the stored owner is not a view, or when it is the element itself.
| `SheetRecord.DrawnBy`, `DesignedBy`, `CheckedBy`, `ApprovedBy` | the `SHEET_*` by-line parameters |
| `SheetRecord.ViewportIds` | the viewports whose sheet is this sheet |
| `SheetRecord.OwnedElementIds` | elements whose `OwnerViewId` is this sheet |
| `SheetRecord.Parameters` | text and whole-number project/shared parameters; `SHEET_SCHEDULED` as `Appears In Sheet List` |
| `ViewportRecord.SheetId` | the referenced sheet |
| `ViewportRecord.DetailNumber` | `Detail Number` parameter (`VIEWPORT_DETAIL_NUMBER`) |

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 @@ -62,8 +62,8 @@ Report options (read the file and print or write a report instead of exporting):
--sketch-owner-dump <path.csv> write the closed sketch loops of every sketch-owning element
--inspect-batch <ids-file> <out.csv> inspect many ids in one pass (ids: one per line or comma separated)
--list-category <categoryId> <out.csv> list the elements of one category
sheets <file.rvt|file.rfa> [output.json] [--r22-layout]
write the sheet catalog (sheets, viewports, limits not decoded) as JSON
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>] [--scale <n>]
[--all-views] [--all-sheets] [--paper A4|A3|A2|A1|A0]
[--list-levels] [--list-views] [--list-sheets]
Expand Down
148 changes: 139 additions & 9 deletions src/RvtIO.Cli/SheetsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
namespace RvtIO.Cli;

/// <summary>
/// <c>rvtio sheets &lt;file.rvt|file.rfa&gt; [output.json] [--r22-layout]</c>: reads a file and writes the sheet catalog of
/// <see cref="SheetCatalog"/> (the sheets, their viewports and what this release does not decode) as JSON to the output
/// path, or to standard output when no path is given. Diagnostics go to standard error.
/// <c>rvtio sheets &lt;file.rvt|file.rfa&gt; [output.json] [--r22-layout] [--where FILTER] [--params] [--csv] [--json]</c>:
/// reads a file and writes the sheet catalog of <see cref="SheetCatalog"/> (the sheets, their viewports and what this
/// release does not decode) as JSON to the output path, or to standard output when no path is given.
/// <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, as in rvt-prt's <c>list --where</c>.
/// <c>--params</c> lists each kept sheet's parameters on standard error, <c>--csv</c> writes them as CSV instead of JSON.
/// Diagnostics go to standard error.
/// Exit codes: 0 written, 1 usage error or an output path that cannot be written, 2 the file cannot be read, 3 a reader
/// limit cut a stream.
/// </summary>
Expand All @@ -23,14 +27,46 @@ internal static class SheetsCommand
internal static int Run(string[] args, TextWriter output, TextWriter error)
{
string? file = null, outputPath = null;
bool r22Layout = false;
foreach (string arg in args)
bool r22Layout = false, showParams = false, csv = false;
var whereTexts = new List<string>();
for (int i = 0; i < args.Length; i++)
{
string arg = args[i];
if (arg == "--r22-layout")
{
r22Layout = true;
continue;
}
if (arg == "--params")
{
showParams = true;
continue;
}
if (arg == "--csv")
{
csv = true;
continue;
}
if (arg == "--json")
{
// The default output; accepted for rvt-prt compatibility.
continue;
}
if (arg == "--where")
{
if (i + 1 >= args.Length)
{
error.WriteLine("sheets --where needs a filter: NAME=VALUE, NAME!=VALUE or NAME~TEXT. " + Usage);
return RvtExitCodes.Usage;
}
whereTexts.Add(args[++i]);
continue;
}
if (arg.StartsWith("--where=", StringComparison.Ordinal))
{
whereTexts.Add(arg["--where=".Length..]);
continue;
}
if (arg.StartsWith("--", StringComparison.Ordinal))
{
error.WriteLine("Unknown option for sheets: " + arg + ". " + Usage);
Expand All @@ -55,6 +91,18 @@ internal static int Run(string[] args, TextWriter output, TextWriter error)
return RvtExitCodes.Usage;
}

var filters = new List<SheetFilter>();
foreach (string text in whereTexts)
{
var parsed = SheetFilter.TryParse(text, out string? parseError);
if (parsed == null)
{
error.WriteLine(parseError + " " + Usage);
return RvtExitCodes.Usage;
}
filters.Add(parsed);
}

SheetCatalog catalog;
try
{
Expand All @@ -72,17 +120,48 @@ internal static int Run(string[] args, TextWriter output, TextWriter error)
return RvtExitCodes.LimitExceeded;
}

string json = JsonSerializer.Serialize(catalog, Options);
if (filters.Count > 0)
{
// A misspelt name stops with the names there are, as in rvt-prt.
var available = AvailableNames(catalog);
foreach (var filter in filters)
{
if (!available.Contains(filter.Name))
{
error.WriteLine($"Unknown sheet parameter '{filter.Name}'. Available: {string.Join(", ", available)}.");
return RvtExitCodes.Usage;
}
}
var kept = catalog.Sheets.Where(sheet => filters.All(filter => filter.Matches(sheet))).ToList();
if (kept.Count == 0)
{
error.WriteLine("[sheets] no sheet matches the --where filters; nothing was written.");
return RvtExitCodes.Usage;
}
catalog = SheetCatalog.FromFiltered(kept, catalog.Viewports.Where(v => kept.Any(s => s.ElementId == v.SheetId)).ToList());
}

if (showParams)
{
foreach (var sheet in catalog.Sheets)
{
error.WriteLine($"{sheet.Number ?? "?"} {sheet.Name ?? ""}");
foreach (var (key, value) in sheet.Parameters)
error.WriteLine($" {key}: {value}");
}
}

string payload = csv ? ToCsv(catalog) : JsonSerializer.Serialize(catalog, Options);
if (outputPath == null)
{
output.WriteLine(json);
output.WriteLine(payload);
}
else
{
string temporary = outputPath + "." + Guid.NewGuid().ToString("N") + ".tmp";
try
{
File.WriteAllText(temporary, json + Environment.NewLine, new System.Text.UTF8Encoding(false));
File.WriteAllText(temporary, payload + Environment.NewLine, new System.Text.UTF8Encoding(false));
File.Move(temporary, outputPath, overwrite: true);
}
catch (Exception exception) when (exception is IOException or UnauthorizedAccessException)
Expand All @@ -103,5 +182,56 @@ internal static int Run(string[] args, TextWriter output, TextWriter error)
return RvtExitCodes.Success;
}

private const string Usage = "Usage: rvtio sheets <file.rvt|file.rfa> [output.json] [--r22-layout]";
private static SortedSet<string> AvailableNames(SheetCatalog catalog)
{
var names = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (string core in new[]
{
"Sheet Number", "Sheet Name", "Sheet Issue Date", "View Scale",
"Drawn By", "Designed By", "Checked By", "Approved By", "Appears In Sheet List",
"SHEET_NUMBER", "SHEET_NAME", "SHEET_ISSUE_DATE", "VIEW_SCALE",
"SHEET_DRAWN_BY", "SHEET_DESIGNED_BY", "SHEET_CHECKED_BY", "SHEET_APPROVED_BY",
"SHEET_SCHEDULED",
})
names.Add(core);
foreach (var sheet in catalog.Sheets)
foreach (var key in sheet.Parameters.Keys)
names.Add(key);
return names;
}

private static string ToCsv(SheetCatalog catalog)
{
var extra = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var sheet in catalog.Sheets)
foreach (var key in sheet.Parameters.Keys)
extra.Add(key);
var lines = new List<string>
{
string.Join(",", new[] { "ElementId", "Number", "Name", "IssueDate", "Scale", "DrawnBy",
"DesignedBy", "CheckedBy", "ApprovedBy" }.Concat(extra).Select(EscapeCsv)),
};
foreach (var sheet in catalog.Sheets)
{
var fields = new List<string?>
{
sheet.ElementId.ToString(), sheet.Number, sheet.Name, sheet.IssueDate,
sheet.Scale?.ToString(), sheet.DrawnBy, sheet.DesignedBy, sheet.CheckedBy, sheet.ApprovedBy,
};
foreach (string key in extra)
fields.Add(sheet.Parameters.TryGetValue(key, out var value) ? value : null);
lines.Add(string.Join(",", fields.Select(EscapeCsv)));
}
return string.Join(Environment.NewLine, lines);
}

private static string EscapeCsv(string? field)
{
field ??= string.Empty;
if (field.Contains('"') || field.Contains(',') || field.Contains('\n') || field.Contains('\r'))
return "\"" + field.Replace("\"", "\"\"") + "\"";
return field;
}

private const string Usage = "Usage: rvtio sheets <file.rvt|file.rfa> [output.json] [--r22-layout] [--where FILTER] [--params] [--csv] [--json]";
}
Loading
Loading