Skip to content
Draft
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: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ rvtio downgrade project2027.rvt --target-profile profile2026.rvt --output projec

Use a profile saved by the target release. `--check` compares class versions,
stored fields, and upgrade identifiers and writes only the optional report.
The element count used in the report reads stored partitions one page at a time.
When writing a project for Revit 2020 or 2021, use a complete `.rvt` saved by
that release. The writer uses project unit formats for 2020 and unit schema
catalogs for 2021. A profile containing only a class table is usable with
Expand All @@ -216,6 +217,8 @@ Older Revit releases cannot represent every newer record. A conversion with
known omitted record owners requires `--allow-loss` and a JSON `--report`.
The report lists affected record owners and known project and analytical omissions.
When a report is requested, the CLI publishes the RVT after saving the report.
With a recognized archive header in both files, the writer converts the
source document storage index and keeps its worksharing data.
Review the report and open the output in the target Revit release before relying
on it. `--restore-legacy-analytics` applies only when writing Revit 2022 from a
Revit 2023 or later project. It requires an earlier Revit 2022 revision of the
Expand Down
43 changes: 28 additions & 15 deletions src/RvtIO.Cli/DowngradeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ internal static int Run(string[] args, TextWriter output, TextWriter error)
if (PathProblem(source, profile, reportPath, outputPath) is { } problem) return Usage(error, problem + " Nothing was read or written.");

string sourceName = Path.GetFileName(source), profileName = Path.GetFileName(profile);
using var chainBuffer = new MemoryStream();
DowngradePlanner.Result result;
try { result = DowngradePlanner.Plan(source, profile, rule); }
try
{
result = DowngradePlanner.Plan(source, profile, rule, chainBuffer: chainBuffer,
countDuringWrite: outputPath is not null && !check);
}
catch (RvtInputException exception)
{
return End(error, reportPath, RvtExitCodes.InputError, exception.Kind, exception.Message, sourceName, profileName, rule);
Expand All @@ -84,33 +89,41 @@ internal static int Run(string[] args, TextWriter output, TextWriter error)
return End(error, reportPath, RvtExitCodes.InputError, "limit-exceeded", exception.Message, sourceName, profileName, rule);
}

var plan = result.Plan;
var inv = CultureInfo.InvariantCulture;
output.WriteLine($"Source: {sourceName} (release {result.SourceRelease}, {plan.SourceClasses.ToString(inv)} classes)");
output.WriteLine($"Profile: {profileName} (release {result.TargetRelease}, {plan.TargetClasses.ToString(inv)} classes)");
output.WriteLine($"Upgrade-identifier rule: {RuleName(rule)}");
output.WriteLine($"Classes in both: {plan.CommonClasses.ToString(inv)}; class versions to lower: {plan.HigherVersions.Count.ToString(inv)}; upgrade-identifier lists to change: {plan.GuidLists.Count.ToString(inv)}");
string elements = plan.ElementsInSourceOnlyClasses is int n ? $"; elements in them: {n.ToString(inv)}" : "; elements not counted";
output.WriteLine($"Classes only in the source: {plan.ClassesOnlyInSource.Count.ToString(inv)}{elements}");
output.WriteLine($"Classes only in the profile: {plan.ClassesOnlyInTarget.Count.ToString(inv)}; classes with different fields: {plan.FieldDifferences.Count.ToString(inv)}");
int emptied = plan.GuidLists.Count(g => g.Result == 0);
if (emptied > 0) output.WriteLine($"Upgrade-identifier lists that become empty: {emptied.ToString(inv)} (the rule yields no identifier for them)");
if (!restoreLegacyAnalytics && result.OmittedContextualMembers is > 0)
error.WriteLine($"warning: Revit 2022 cannot open independent analytical members. Downgrade omits {result.OmittedContextualMembers.Value.ToString(inv)} AnalyticalMember elements.");
if (result.CountFailure != null) error.WriteLine($"warning: the elements were not counted: {result.CountFailure}.");
void PrintPlan()
{
var plan = result.Plan;
output.WriteLine($"Source: {sourceName} (release {result.SourceRelease}, {plan.SourceClasses.ToString(inv)} classes)");
output.WriteLine($"Profile: {profileName} (release {result.TargetRelease}, {plan.TargetClasses.ToString(inv)} classes)");
output.WriteLine($"Upgrade-identifier rule: {RuleName(rule)}");
output.WriteLine($"Classes in both: {plan.CommonClasses.ToString(inv)}; class versions to lower: {plan.HigherVersions.Count.ToString(inv)}; upgrade-identifier lists to change: {plan.GuidLists.Count.ToString(inv)}");
string elements = plan.ElementsInSourceOnlyClasses is int n ? $"; elements in them: {n.ToString(inv)}" : "; elements not counted";
output.WriteLine($"Classes only in the source: {plan.ClassesOnlyInSource.Count.ToString(inv)}{elements}");
output.WriteLine($"Classes only in the profile: {plan.ClassesOnlyInTarget.Count.ToString(inv)}; classes with different fields: {plan.FieldDifferences.Count.ToString(inv)}");
int emptied = plan.GuidLists.Count(g => g.Result == 0);
if (emptied > 0) output.WriteLine($"Upgrade-identifier lists that become empty: {emptied.ToString(inv)} (the rule yields no identifier for them)");
if (!restoreLegacyAnalytics && result.OmittedContextualMembers is > 0)
error.WriteLine($"warning: Revit 2022 cannot open independent analytical members. Downgrade omits {result.OmittedContextualMembers.Value.ToString(inv)} AnalyticalMember elements.");
if (result.CountFailure != null) error.WriteLine($"warning: the elements were not counted: {result.CountFailure}.");
}
if (!result.CountInWriter) PrintPlan();

if (outputPath != null)
{
DowngradeWriter.DowngradeWriteResult written;
try
{
written = DowngradeWriter.Write(source, profile, outputPath, rule, includeOmittedAnalytics: reportPath is not null,
written = DowngradeWriter.Write(source, profile, outputPath, result, includeOmittedAnalytics: reportPath is not null,
restoreLegacyAnalytics: restoreLegacyAnalytics, allowLoss: allowLoss,
beforePublish: reportPath is null ? null : prepared =>
{
if (WriteReport(error, reportPath, WriteReportBody(result, sourceName, profileName, prepared),
RvtExitCodes.Success) != RvtExitCodes.Success)
throw new ReportWriteFailedException();
}, chainBuffer: chainBuffer, afterCensus: counted =>
{
result = counted;
PrintPlan();
});
if (written.RestoredAnalyticalMembers is { } restored)
output.WriteLine($"Restored analytical members: {restored.Count.ToString(inv)}. Panels: {(written.RestoredAnalyticalPanels?.Count ?? 0).ToString(inv)}. Point supports: {(written.RestoredPointSupports?.Count ?? 0).ToString(inv)}. Line supports: {(written.RestoredLineSupports?.Count ?? 0).ToString(inv)}.");
Expand Down
5 changes: 3 additions & 2 deletions src/RvtIO/Parsing/PagedGzipStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ internal static class PagedGzipStream
if (body == null) return null;
int start = IsGzipHeader(body, 0) ? 0 : IsGzipHeader(body, PrefixLength) ? PrefixLength : -1;
if (start < 0) return null;
return Inflate(body, start);
return InflateMember(body, start);
}

/// <summary>Inflates one gzip member and requires its CRC-32 and length trailer right after the deflate data.
/// GZipStream cannot be used: it does not fail on a member cut before the trailer.</summary>
private static byte[]? Inflate(byte[] body, int start)
internal static byte[]? InflateMember(byte[] body, int start)
{
if (start < 0 || start > body.Length - 18 || !IsGzipHeader(body, start)) return null;
int deflateStart = HeaderEnd(body, start);
if (deflateStart < 0) return null;
var inflater = new Inflater(noHeader: true);
Expand Down
Loading
Loading