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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RvtIO is a .NET library and command line tool that reads Autodesk Revit projects
- Queries elements through `FilteredElementCollector`.
- Exports IFC2X3 coordination view (default) and IFC4 (ISO 16739-1:2018 / ADD2 TC1; `ReferenceView_V1.2` and `DesignTransferView_V1.0`), with shared JSON/API configuration presets and optional Revit parameters as property sets.
- Exports binary glTF 2.0 (`.glb`) directly via `GlbExporter` / `--glb` in Y-up metres with shared family symbol meshes, PBR colors/transparency, and element/material metadata in `extras`.
- Exports element CSV with identifiers shared with GLB and quantities in SI units.
- Writes compact JSON or a full JSON dump with every parameter and geometry.
- Returns the triangle meshes of the model elements, with one shared mesh per family symbol for repeated instances (`ElementMeshes`).
- Lists the sheets of a file and the viewports placed on them (`SheetCatalog`), with the sheet number, name, issue date, by-lines, the viewports of each sheet and the elements each sheet owns. Page size, view placement and 2D content are not decoded yet; the catalog reports each limit.
Expand Down Expand Up @@ -87,10 +88,10 @@ rvtio project.rvt project.glb
Export multiple formats in a single read:

```sh
rvtio project.rvt --ifc project.ifc --glb project.glb --compact-json project.compact.json --scene project.scene.json
rvtio project.rvt --ifc project.ifc --glb project.glb --csv elements.csv --compact-json project.compact.json --scene project.scene.json
```

A `.ifc` output path selects IFC and a `.glb` output path selects binary glTF 2.0 (GLB). Any other output path selects JSON, which is compact by default. When `--ifc`, `--glb`, `--compact-json`, `--full-json`, or `--scene` are specified, the model is read once and each requested format is exported sequentially. Positional output arguments remain fully backward compatible. Single-output and multi-output exports produce byte-identical files. On Revit 2023+ (own-schema) models, JSON formats retain their wide-schema representation by default (use `--r22-layout` to export JSON in Revit 2022 layout too), while IFC, GLB, and Scene exports use the Revit 2022 geometry layout, sharing decoded geometry and quantities without reading the model again. If no output path is given, the tool writes `output.json`. Diagnostics go to standard error. See [GLB export](docs/glb-export.md).
A `.ifc` output path selects IFC and a `.glb` output path selects binary glTF 2.0 (GLB). Any other positional output path selects JSON, which is compact by default. With explicit output options, the model is read once and each requested format is exported sequentially. Single-output and multi-output exports produce byte-identical files. On Revit 2023+ (own-schema) models, JSON formats retain their wide-schema representation by default (use `--r22-layout` to export JSON in Revit 2022 layout too), while IFC, GLB, CSV, and Scene exports use the Revit 2022 layout. If no output path is given, the tool writes `output.json`. Diagnostics go to standard error. See [GLB export and element CSV](docs/glb-export.md).

List the sheets and the viewports placed on them:

Expand Down
17 changes: 16 additions & 1 deletion docs/glb-export.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,19 @@ rvtio project.rvt --glb project.glb --ifc project.ifc --compact-json project.jso

With `--report`, a GLB-only run includes element, node and mesh counts in `export`. When IFC or JSON provides the main `export` summary, the GLB counts appear in `glbExport`.

When `--glb` is combined with `--ifc`, `--scene`, `--compact-json`, or `--full-json`, the `.rvt` file is read once (and `ElementMeshes` is extracted once when paired with `--scene`).
When `--glb` is combined with `--csv`, `--ifc`, `--scene`, `--compact-json`, or `--full-json`, the `.rvt` file is read once (and `ElementMeshes` is extracted once when paired with `--scene`).

## Element CSV

```sh
rvtio project.rvt --csv elements.csv
rvtio project.rvt --glb project.glb --csv elements.csv
```

The CSV has one record per decoded element, sorted by `elementId`, including types and elements without geometry.
It excludes orphan geometry blocks and discovered records outside an exact element table. Join the CSV to glTF node
`extras.elementId` from the same model. The CSV and GLB also share `uniqueId` and `ifcGuid` when available.

The measurement columns `length_m`, `area_m2`, and `volume_m3` contain stored Revit quantities converted to metres,
square metres, and cubic metres. Missing or approximate measurements are blank, and stored zeroes are written as zero.
The CSV uses UTF-8 with a BOM and invariant decimal formatting. The library API is `RvtIO.Csv.ElementCsvExporter.Export`.
24 changes: 18 additions & 6 deletions src/RvtIO.Cli/ExportCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using RvtIO.Internal;
using RvtIO;
using RvtIO.Compact;
using RvtIO.Csv;
using RvtIO.BuiltIns;
using RvtIO.Ifc;
using RvtIO.Gltf;
Expand All @@ -11,7 +12,7 @@
internal static partial class Program
{
/// <summary>The values of the command line that decide the export.</summary>
private sealed record ExportArguments(string[] Args, string RvtPath, string? IfcPath, string? GlbPath, string? CompactJsonPath, string? FullJsonPath, string? ScenePath,
private sealed record ExportArguments(string[] Args, string RvtPath, string? IfcPath, string? GlbPath, string? CsvPath, string? CompactJsonPath, string? FullJsonPath, string? ScenePath,
string? ExternalDumpPath, string? ExternalDumpClassPrefix,
IfcProfile Profile, string JsonClassPrefix,
IfcExportConfiguration MergedIfcConfiguration, string? SaveIfcConfigPath);
Expand All @@ -32,15 +33,16 @@ private static ExportInput ReadExportInput(string path, RvtReaderOptions options
return new(model, json, names, reader.WideState is { } wide ? new JsonReadFacts(wide, compact, debugNative) : names, quantities, state.ElemTable.Keys);
}

// The export: reads the file and writes the requested formats (IFC, GLB, scene JSON, compact JSON, full JSON).
// The export: reads the file and writes the requested formats (IFC, GLB, element CSV, scene JSON, compact JSON, full JSON).
private static int Export(ExportArguments arguments)
{
var (args, rvtPath, ifcPath, glbPath, compactJsonPath, fullJsonPath, scenePath, externalDumpPath, externalDumpClassPrefix, profile, jsonClassPrefix, mergedIfcConfig, saveIfcConfigPath) = arguments;
var (args, rvtPath, ifcPath, glbPath, csvPath, compactJsonPath, fullJsonPath, scenePath, externalDumpPath, externalDumpClassPrefix, profile, jsonClassPrefix, mergedIfcConfig, saveIfcConfigPath) = arguments;
WarnIfRevitLocalization(args);

var exportOutputs = new List<(string Option, string Path)>();
if (ifcPath != null) exportOutputs.Add(("--ifc", ifcPath));
if (glbPath != null) exportOutputs.Add(("--glb", glbPath));
if (csvPath != null) exportOutputs.Add(("--csv", csvPath));
if (compactJsonPath != null) exportOutputs.Add(("--compact-json", compactJsonPath));
if (fullJsonPath != null) exportOutputs.Add(("--full-json", fullJsonPath));
if (scenePath != null) exportOutputs.Add(("--scene", scenePath));
Expand Down Expand Up @@ -71,7 +73,7 @@ private static int Export(ExportArguments arguments)
}
}

bool needIfcLayout = ifcPath != null || scenePath != null || glbPath != null;
bool needIfcLayout = ifcPath != null || scenePath != null || glbPath != null || csvPath != null;
bool multiJson = compactJsonPath != null && fullJsonPath != null;
bool needR22 = needIfcLayout || multiJson;
bool hasJsonOutput = compactJsonPath != null || fullJsonPath != null;
Expand All @@ -84,7 +86,7 @@ private static int Export(ExportArguments arguments)
ExternalDumpClassPrefix = externalDumpClassPrefix,
SystemFamilyNameLocale = profile == RvtIO.Ifc.IfcProfile.Current ? "ENU" : null,
SeparateFacesWithDistinctOpenings = profile == RvtIO.Ifc.IfcProfile.Current,
// IFC, Scene, and multi-JSON exports decode geometry with the Revit 2022 readers; --no-r22-layout keeps the 64-bit schema path alone
// CSV uses the same element layout as GLB; --no-r22-layout keeps the 64-bit schema path alone.
R22Layout = (needR22 && !noR22) || explicitR22,
PreserveWideLayout = (needIfcLayout || multiJson) && hasJsonOutput && !explicitR22 && !noR22,
ResolveCurrentCopies = RvtIO.Cli.CurrentCopiesOption.Resolve(args),
Expand Down Expand Up @@ -165,10 +167,12 @@ private static int Export(ExportArguments arguments)
var jsonState = input.JsonFacts;
var ifcModel = input.Geometry;
GlbExportResult? glbResult = null;
var sceneDocument = scenePath != null || glbPath != null || csvPath != null
? RvtDocument.ForSceneExport(ifcModel) : null;

if (scenePath != null || glbPath != null)
{
var doc = RvtDocument.ForSceneExport(ifcModel);
var doc = sceneDocument!;
var sharedMeshes = RvtIO.Meshes.ElementMeshes.Extract(doc);
if (scenePath != null)
{
Expand Down Expand Up @@ -206,6 +210,14 @@ private static int Export(ExportArguments arguments)
}
}

if (csvPath != null)
{
var swCsv = System.Diagnostics.Stopwatch.StartNew();
int count = ElementCsvExporter.Export(sceneDocument!, csvPath);
Console.Error.WriteLine($"Timing: csv {swCsv.Elapsed.TotalSeconds:F1}s");
Console.Error.WriteLine($"CSV written to {csvPath} ({count} elements)");
}

if (ifcPath != null)
{
// Without the option the current profile exports the rooms of the last project phase that exists as a phase element (the
Expand Down
17 changes: 10 additions & 7 deletions src/RvtIO.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ internal static partial class Program
Usage: rvtio <file.rvt|file.rfa> [output.ifc|output.json|output.glb] [options]
rvtio --help | --version

Reads a Revit file and writes IFC, GLB, JSON, or an IOScene scene. A .ifc output path writes IFC and a .glb
Reads a Revit file and writes IFC, GLB, element CSV, JSON, or an IOScene scene. A .ifc output path writes IFC and a .glb
output path writes binary glTF 2.0 (GLB); any other path writes JSON (default output.json). Pass multiple output
options (--ifc, --glb, --scene, --compact-json, --full-json) to write several formats from a single file read.
options (--ifc, --glb, --csv, --scene, --compact-json, --full-json) to write several formats from a single file read.
Diagnostics go to standard error.

Export options:
--ifc <file.ifc> write IFC output to the specified path
--glb <file.glb> write binary glTF 2.0 (.glb) output to the specified path
--csv <file.csv> write one record per element with GLB identifiers and SI quantities
--scene <file.json> write IOScene scene JSON to the specified path
--compact-json [file.json] write compact JSON (optionally to the specified path)
--full-json <file.json> write the full JSON dump to the specified path
Expand Down Expand Up @@ -130,7 +131,7 @@ apply an ordered batch of supported parameter assignments and clears atomically
// Options that take one value, and options that take two; every other option starting with "--" is a switch.
private static readonly HashSet<string> OneValueOptions =
[
"--ifc", "--glb", "--scene", "--full-json", "--json",
"--ifc", "--glb", "--csv", "--scene", "--full-json", "--json",
"--ifc-profile", "--ifc-phase", "--ifc-room-phase",
RvtIO.Cli.IfcConfigurationOptions.SchemaOption,
RvtIO.Cli.IfcConfigurationOptions.ModelViewOption,
Expand Down Expand Up @@ -213,6 +214,7 @@ internal static int Main(string[] args)

string? ifcPath = null;
string? glbPath = null;
string? csvPath = null;
string? scenePath = null;
string? fullJsonPath = null;
string? explicitJsonPath = null;
Expand All @@ -222,7 +224,7 @@ internal static int Main(string[] args)
for (int i = 1; i < args.Length; i++)
{
string arg = args[i];
if (arg is "--ifc" or "--glb" or "--scene" or "--full-json" or "--json")
if (arg is "--ifc" or "--glb" or "--csv" or "--scene" or "--full-json" or "--json")
{
if (i + 1 >= args.Length || args[i + 1].StartsWith("--", StringComparison.Ordinal) || string.IsNullOrWhiteSpace(args[i + 1]))
{
Expand All @@ -232,6 +234,7 @@ internal static int Main(string[] args)
string path = args[++i];
if (arg == "--ifc") ifcPath = path;
else if (arg == "--glb") glbPath = path;
else if (arg == "--csv") csvPath = path;
else if (arg == "--scene") scenePath = path;
else if (arg == "--full-json") fullJsonPath = path;
else if (arg == "--json") explicitJsonPath = path;
Expand Down Expand Up @@ -293,7 +296,7 @@ static bool IsNonJsonPositionalExtension(string path) =>
: "output.json";
}

bool anyExplicitOutput = ifcPath != null || glbPath != null || scenePath != null || compactJsonPath != null || fullJsonPath != null;
bool anyExplicitOutput = ifcPath != null || glbPath != null || csvPath != null || scenePath != null || compactJsonPath != null || fullJsonPath != null;
if (!anyExplicitOutput)
{
if (jsonFull) fullJsonPath = "output.json";
Expand Down Expand Up @@ -407,7 +410,7 @@ static bool IsNonJsonPositionalExtension(string path) =>
&& !RvtIO.Cli.IfcConfigurationOptions.CanSaveConfiguration(
saveConfigPath, hasIfcOutput || !rvtPath.StartsWith("--", StringComparison.Ordinal) ? rvtPath : null,
cliIfcOptions.ConfigPath, hasIfcOutput ? [
ifcPath, glbPath, compactJsonPath, fullJsonPath, scenePath, ValueOf(args, "--report"), ValueOf(args, "--dev-external-dump"),
ifcPath, glbPath, csvPath, compactJsonPath, fullJsonPath, scenePath, ValueOf(args, "--report"), ValueOf(args, "--dev-external-dump"),
..RvtIO.Cli.ReportPathOption.DumpOptions.Select(option => ValueOf(args, option)),
] : []))
return 1;
Expand Down Expand Up @@ -504,7 +507,7 @@ static bool IsNonJsonPositionalExtension(string path) =>
if (inspectBatchIdsFile != null && inspectBatchOutPath != null) return InspectBatch(rvtPath, inspectBatchIdsFile, inspectBatchOutPath);
if (listCategoryOutPath != null) return ListCategory(rvtPath, listCategoryId, listCategoryOutPath);

return Export(new ExportArguments(args, rvtPath, ifcPath, glbPath, compactJsonPath, fullJsonPath, scenePath,
return Export(new ExportArguments(args, rvtPath, ifcPath, glbPath, csvPath, compactJsonPath, fullJsonPath, scenePath,
externalDumpPath, externalDumpClassPrefix, resolvedIfcConfiguration.Profile,
jsonClassPrefix, mergedIfcConfiguration, cliIfcOptions.SaveConfigPath));
}
Expand Down
2 changes: 1 addition & 1 deletion src/RvtIO.Cli/ReportPathOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static class ReportPathOption
/// <summary>The dump options of the export whose value is an output path.</summary>
public static readonly string[] DumpOptions =
["--dev-candidates", "--dev-trace", "--dev-facts", "--dev-solids", "--dev-user-params", "--dev-collisions",
"--ifc", "--glb", "--scene", "--full-json", "--json"];
"--ifc", "--glb", "--csv", "--scene", "--full-json", "--json"];

/// <summary>Every file the command line names as an output: the input never, the export and every named dump.</summary>
public static IEnumerable<string> OutputPaths(string[] args, string rvtPath, string? outputPath, string? externalDumpPath)
Expand Down
Loading
Loading