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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ 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).

Compare a model's shared parameter definitions against a Revit shared parameter file by GUID.

```sh
rvtio audit-shared-parameters project.rvt shared-parameters.txt --report shared-parameter-audit.json
```

The command reads both inputs and lists missing definitions, metadata differences, incompatible types and collisions.
See the [audit report format](docs/shared-parameter-audit.md).

Inspect file metadata or inventory a folder recursively without reading geometry or `Partitions`:

```sh
Expand Down
34 changes: 34 additions & 0 deletions docs/shared-parameter-audit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Shared parameter audit

Run the audit against a Revit project, template, or standalone family and a Revit shared parameter file (FOP):

```sh
rvtio audit-shared-parameters project.rvt shared-parameters.txt --report shared-parameter-audit.json
```

Omit `--report` to print the JSON to standard output. The command opens both inputs for reading. It reads the
parameter definitions of the selected document, including definitions with no assigned values. Audit a standalone
family file separately to check its own definitions. The shared parameter file follows the
[Autodesk definition file format](https://help.autodesk.com/cloudhelp/2024/ENU/Revit-API/files/Revit_API_Developers_Guide/Basic_Interaction_with_Revit_Elements/Parameters/Shared_Parameters/Revit_API_Revit_API_Developers_Guide_Basic_Interaction_with_Revit_Elements_Parameters_Shared_Parameters_Definition_File_html.html).
The command accepts UTF-8 and UTF-16 with a byte-order mark for UTF-16.

The `rvtio-shared-parameter-audit/1` report lists both sides for each GUID in `parameters`, with model element IDs
and FOP line numbers. A one-to-one match compares the exact name, description when the FOP supplies it, and data type.
For `FAMILYTYPE`, it also compares the target category ID. Empty descriptions in the FOP are compared as empty text.
An empty `findings` array means all comparable fields of the pair agree.

| Finding | Meaning |
| --- | --- |
| `model-only`, `fop-only` | The GUID appears on one side. A FOP can legitimately contain definitions the document does not use. |
| `name-mismatch`, `description-mismatch` | The GUID matches and the names or descriptions differ. |
| `incompatible-type` | The verified data types differ, or the verified family type category differs. |
| `type-unverified`, `description-unverified` | The comparison needs a type, category, or description the reader could not establish. Unsupported data types keep their raw definition class and spec ID when available. |
| `duplicate-model-guid`, `duplicate-fop-guid` | More than one definition or FOP row on the same side uses this GUID. All candidates are listed. |
| `not-confirmed-in-model` | A FOP GUID was absent from the readable model definitions and the model inventory is partial. |

The separate `nameCollisions` array lists case-insensitive names used by more than one GUID across either input.
The `unreadableDefinitions` array lists model element IDs whose records were unreadable or ambiguous.

Exit codes are `0` for a completed audit even when it reports differences, `1` for bad arguments or a report that
cannot be written, `2` for unreadable inputs or invalid FOP syntax, `3` for a reader limit, and `6` for a report
with unreadable or ambiguous definitions.
72 changes: 70 additions & 2 deletions docs/test-fixtures.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ A file may lie directly in the folder or in one level of subfolders (`2020`, `20
| `TestData/*.bin` | class blocks captured from project files (38 files, below) |

`PageCodecSampleTests` reads every `.rvt` file in the folder and in one level of subfolders, whatever its name, and skips streams over
128 MB.
128 MB. Its short-page test also reads `.rfa`, `.rte`, and `.rft` files. It checks the parity of short tails in gzip streams that pass
their CRC and length checks and in partition streams that pass the framing checks. See [Native short pages](#native-short-pages).

`ContainerRewriterSampleTests` copies every `.rvt` file in the folder and in one level of subfolders to a temporary file (deleted after
each file; it needs free disk space for the largest file) and compares the compact JSON of the copy with that of the source for the ten largest files of up to 8 MB.
Expand Down Expand Up @@ -48,6 +49,73 @@ needs no code of its own to skip. Tests that write diagnostic dumps write them t
system temporary folder (`TestFiles.Scratch`), one folder per test process, so concurrent runs (both target frameworks of one
`dotnet test`, or runs from other checkouts) never share a file; no test uses a fixed absolute path.

## Native short pages

In the measured short pages, bit `b` (least significant bit first in each byte) belongs to lane `b mod D`, where `D` is an odd
number of lanes. Each lane stores `k - p` data bits followed by `p` parity bits. The page stores the planes for those bits in order,
then zero bits up to the next byte boundary. Its stored length is `ceil(D × k / 8)`.

The parity is the remainder of the lane's data polynomial multiplied by `y^(p + 2^p - 1 - k)` and divided by the generator
over GF(2). The term `2^p - 1 - k` accounts for the omitted low-order zero coefficients of shortened lanes. In the samples,
shortened lanes occur with `D = 65`. With more lanes, `k = 2^p - 1`.

| Parity bits per lane (`p`) | Full lane length | Generator |
|---:|---:|---|
| 4 | 15 | `y⁴ + y³ + 1` |
| 5 | 31 | `y⁵ + y³ + 1` |
| 6 | 63 | `y⁶ + y⁵ + 1` |
| 7 | 127 | `y⁷ + y⁶ + 1` |
| 9 | 511 | `y⁹ + y⁵ + 1` |
| 11 | 2,047 | `y¹¹ + y⁹ + 1` |

The reference test checks stored tails from 82 bytes up to the first long-tail size and requires exactly one parity match.
`PageCodec.Verify` tries every confirmed layout that fits the stored length. A matching layout gives `Valid`. If layouts fit
the length but fail parity or byte padding, the result is `BadTail`. A length with no verified layout gives `UnsupportedTail`.

For writing, `PageCodec` selects the first row whose capacity holds the content plus the reserved bits. A row's capacity is
`max D × (2^p - 1 - p)` bits. The writer uses 65 lanes when they fit and rounds the required lane count up to an odd number
otherwise. It writes unused bits as zeros. These parameters are inferred from stored lane counts, parity, and the byte offsets
of the gzip or partition terminators in Revit-saved files. At some lengths several reserved-bit counts explain the same layout.

| Parity bits (`p`) | Max lanes (`D`) | Reserved bits | Last content length for this row (bytes) |
|---:|---:|---:|---:|
| 4 | 77 | 4 | 105 |
| 5 | 79 | 4 | 256 |
| 6 | 77 | 4 | 548 |
| 7 | 85 | 5 | 1,274 |
| 9 | 81 | 7 | 5,081 |
| 11 | 65 | 9 | 16,541 |

Longer tails use the existing 11-bit layout with at least 67 lanes. `EncodePadded` pads a shorter tail to 44 content bytes
when necessary. For an empty stream or a stream ending exactly on a full page, it appends a 44-byte zero tail. Observed native
gzip pages also exercise the writer's layout selection in the reference test.

Native saves showed both sides of the 105/106, 256/257, 548/549, 1,274/1,275, and 5,081/5,082 transitions. Revit 2025
saved a `Global/DocumentIncrementTable` tail with exactly 256 content bytes (an 8-byte prefix and a 248-byte gzip member).
The 307 stored bytes matched the 5-bit code across all 79 lanes, and a native 257-byte tail used the 6-bit code.
Native Revit 2025 partition streams also showed both sides of the 16,541/16,542 transition. The 16,541-byte tail used
65 lanes and occupied 16,632 stored bytes. The 16,542-byte tail used 67 lanes and occupied 17,144 stored bytes. Both used
full-length lanes of 2,047 bits with 11 parity bits per lane.
Revit 2025 opened generated copies on both sides of every writer transition, including 256/257 and 16,541/16,542,
and returned the original model data.

The native boundary tests read `crcio-tail-<length>.rvt` from `RVTIO_TEST_FILES`. Use the exact decimal content length
without separators, for example `crcio-tail-1274.rvt`. Each case skips if its RVT is absent.

| Content lengths (bytes) | Expected parity bits per lane | Required single-page stream |
|---|---|---|
| 105 / 106 | 4 / 5 | `Global/PartitionTable` / `Global/DocumentIncrementTable` |
| 256 / 257 | 5 / 6 | `Global/DocumentIncrementTable` |
| 548 / 549 | 6 / 7 | A partition / `Global/DocumentIncrementTable` |
| 1,274 / 1,275 | 7 / 9 | A partition |
| 5,081 / 5,082 | 9 / 11 | A partition |
| 16,541 / 16,542 | 11 / 11 | A partition |

`NativeShortTailBoundary_UsesTheExpectedParityWidth` measures gzip streams through the end of the member, including
the stream prefix. `NativePartitionTailBoundary_MatchesTheExpectedLayout` measures partition streams through the
terminal marker. Both tests compare the native and re-encoded parity layouts. Changing one parity bit must report
a bad tail while gzip decoding or partition framing still succeeds.

## Format corpus regression check

Set `RVTIO_FORMAT_CORPUS` to a local JSON manifest and run the format corpus test.
Expand Down Expand Up @@ -123,7 +191,7 @@ Run with the private files: `RVTIO_TEST_FILES=<folder> dotnet test` (PowerShell:
| `IfcExporterSlabQuantitiesSampleTests` | 3 | 3 | rstbasicsampleproject.rvt, struct25.rvt |
| `MultistoryStairCopyTests` | 1 | 1 | rac_advanced_sample_project.rvt |
| `OwnElementClassTests` | 1 | 1 | TESTFILE.rvt |
| `PageCodecSampleTests` | 2 | 2 | any `.rvt` project files |
| `PageCodecSampleTests` | 15 | 15 | `.rvt` projects, and `.rfa`, `.rte`, or `.rft` for the short-page census |
| `PartitionFramingFuzzTests` | 1 | 1 | TESTFILE.rvt |
| `ProjectLengthUnitTests` | 1 | 1 | One Way Sign in Route Analysis.rfa |
| `R22TranscoderTests` | 2 | 2 | Test_2025.rvt, TESTFILE.rvt |
Expand Down
2 changes: 2 additions & 0 deletions docs/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
href: glb-export.md
- name: Writing and save-as
href: writing.md
- name: Shared parameter audit
href: shared-parameter-audit.md
- name: Export report and exit codes
href: export-report.md
- name: Coverage report
Expand Down
4 changes: 3 additions & 1 deletion src/RvtIO.Cli/DowngradeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,16 @@ private static object Report(DowngradePlanner.Result result, string sourceName,
};
}

internal static string SerializeReport(object report) => JsonSerializer.Serialize(report, JsonOptions);

// The report is written beside its target and moved over it, so a failed write leaves no half file and a link keeps its content.
internal static int WriteReport(TextWriter error, string? reportPath, object report, int exitCode)
{
if (reportPath == null) return exitCode;
string temporary = reportPath + "." + Guid.NewGuid().ToString("N") + ".tmp";
try
{
File.WriteAllText(temporary, JsonSerializer.Serialize(report, JsonOptions), new UTF8Encoding(false));
File.WriteAllText(temporary, SerializeReport(report), new UTF8Encoding(false));
File.Move(temporary, reportPath, overwrite: true);
}
catch (Exception exception) when (exception is IOException or UnauthorizedAccessException or ArgumentException or NotSupportedException)
Expand Down
3 changes: 3 additions & 0 deletions src/RvtIO.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ replace a supported parameter in a local Revit 2020-2027 project
replace a supported parameter on a type in a local Revit 2020-2027 family
edit-parameters <source.rvt|source.rfa> <output.rvt|output.rfa> <edits.json>
apply an ordered batch of supported parameter assignments and clears atomically
audit-shared-parameters <model.rvt|model.rte|model.rfa> <shared-parameters.txt> [--report <report.json>]
compare shared parameter definitions by GUID and write a JSON report
coverage <file.rvt> [--report <report.json>] [--top <n>]
(first argument) count the records of the partition streams that the class schema of the
file walks to their last byte, per channel and class; writes nothing but the report
Expand Down Expand Up @@ -189,6 +191,7 @@ internal static int Main(string[] args)
if (args[0] == "set-parameter") return RvtIO.Cli.SetParameterCommand.Run(args[1..], Console.Out, Console.Error);
if (args[0] == "set-family-parameter") return RvtIO.Cli.SetParameterCommand.Run(args[1..], Console.Out, Console.Error, familyFile: true);
if (args[0] == "edit-parameters") return RvtIO.Cli.SetParameterCommand.RunBatch(args[1..], Console.Out, Console.Error);
if (args[0] == "audit-shared-parameters") return RvtIO.Cli.SharedParameterAuditCommand.Run(args[1..], Console.Out, Console.Error);
if (args[0] == "coverage") return RvtIO.Cli.CoverageCommand.Run(args[1..], Console.Out, Console.Error);
if (args[0] == "info") return RvtIO.Cli.InfoCommand.Run(args[1..], Console.Out, Console.Error);
if (args[0] == "diff") return RvtIO.Cli.DiffCommand.Run(args[1..], Console.Out, Console.Error);
Expand Down
Loading
Loading