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 @@ -61,10 +61,11 @@ Export full JSON, including every parameter and geometry:
rvtio project.rvt project.full.json --json-full
```

Export IFC with Revit parameters as property sets:
Export IFC with Revit parameters as property sets (optionally converting values to IFC/SI units and using display names):

```sh
rvtio project.rvt project.parameters.ifc --ifc-revit-parameters
rvtio project.rvt project.parameters.ifc --ifc-revit-parameters --ifc-revit-parameter-units ifc --ifc-revit-parameter-names display
```

Export IFC4 (`ReferenceView_V1.2` by default, or `DesignTransferView_V1.0`) independently of `Current`/`Legacy` profiles, or drive exports through a shared JSON configuration preset (`--ifc-preset`, `--ifc-config`, `--ifc-save-config`, `--ifc-capabilities`):
Expand Down
2 changes: 2 additions & 0 deletions docs/ifc-export.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Calling `configuration.Validate()`, `configuration.Resolve()`, or running an exp
| `propertySets.exportIfcCommonPropertySets` | `SchemaOrViewScoped` | `true` | `true` | Standard `Pset_*Common` property sets are always emitted. |
| `propertySets.exportRevitPropertySets` | `Supported` | `true`, `false` | `false` | Opt-in export of Revit parameters. |
| `propertySets.groupRevitParametersByGroup` | `Supported` | `true`, `false` | `false` | Groups Revit parameter sets per group (implies `exportRevitPropertySets`). |
| `propertySets.revitParameterUnits` | `Supported` | `internal`, `ifc` | `internal` (untyped) | Converts length, area, volume, and angle to IFC units and other physical specs to SI units when `ifc`, and assigns the project unit of each converted measure. A parameter whose spec neither the file nor the API definitions give keeps its stored number as `IfcReal`; `IfcMonetaryMeasure` has no currency unit. |
| `propertySets.revitParameterNames` | `Supported` | `builtin`, `display` | `builtin` (untyped) | Uses parameter display names (with `BuiltInParameter` in `Description`) and resolves user parameter names when `display`. Property names are unique within a set: when two parameters share a name, each gets ` [parameter id]` appended (also with an explicit `builtin`). The CLI options for names and units turn the Revit property sets on, with `--ifc-config` too. |
| `propertySets.exportSchedulesAsPropertySets` | `Unsupported` | `false` | `false` | Schedule Psets are not implemented; `true` fails validation. |
| `mappings.useRevitIfcExportAsParameters` | `Supported` | `true` | `true` | Reads `IfcExportAs` / `IfcExportType`; `false` fails validation. |
| `mappings.familyMappingTablePath` | `Unsupported` | `null` | `null` | External mapping files fail validation if non-empty. |
Expand Down
42 changes: 38 additions & 4 deletions src/RvtIO.Cli/IfcConfigurationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ internal sealed record IfcCliOptions(
string? ConfigPath,
string? SaveConfigPath,
bool NoSpaces,
bool ShowCapabilities);
bool ShowCapabilities,
IfcRevitParameterUnits? RevitParameterUnits,
IfcRevitParameterNames? RevitParameterNames);

internal static class IfcConfigurationOptions
{
Expand All @@ -23,10 +25,12 @@ internal static class IfcConfigurationOptions
public const string SaveConfigOption = "--ifc-save-config";
public const string NoSpacesOption = "--ifc-no-spaces";
public const string CapabilitiesOption = "--ifc-capabilities";
public const string RevitParameterUnitsOption = "--ifc-revit-parameter-units";
public const string RevitParameterNamesOption = "--ifc-revit-parameter-names";

public static bool TryParse(string[] args, out IfcCliOptions options, out string? error)
{
options = new IfcCliOptions(null, null, null, null, null, false, false);
options = new IfcCliOptions(null, null, null, null, null, false, false, null, null);
error = null;

IfcSchema? schema = null;
Expand All @@ -36,6 +40,8 @@ public static bool TryParse(string[] args, out IfcCliOptions options, out string
string? saveConfigPath = null;
bool noSpaces = false;
bool showCapabilities = false;
IfcRevitParameterUnits? revitParameterUnits = null;
IfcRevitParameterNames? revitParameterNames = null;

string? ReadSingleValue(string flag, ref int index, ref bool seen)
{
Expand All @@ -48,6 +54,7 @@ public static bool TryParse(string[] args, out IfcCliOptions options, out string
}

bool seenSchema = false, seenView = false, seenPreset = false, seenConfig = false, seenSaveConfig = false;
bool seenParamUnits = false, seenParamNames = false;
for (int i = 0; i < args.Length; i++)
{
switch (args[i])
Expand Down Expand Up @@ -114,10 +121,33 @@ public static bool TryParse(string[] args, out IfcCliOptions options, out string
case CapabilitiesOption:
showCapabilities = true;
break;
case RevitParameterUnitsOption:
{
string? raw = ReadSingleValue(RevitParameterUnitsOption, ref i, ref seenParamUnits);
if (raw is null || !IfcExportOptionParser.TryParseRevitParameterUnits(raw, out var parsed))
{
error = $"{RevitParameterUnitsOption} requires a supported unit system: ifc, internal.";
return false;
}
revitParameterUnits = parsed;
break;
}
case RevitParameterNamesOption:
{
string? raw = ReadSingleValue(RevitParameterNamesOption, ref i, ref seenParamNames);
if (raw is null || !IfcExportOptionParser.TryParseRevitParameterNames(raw, out var parsed))
{
error = $"{RevitParameterNamesOption} requires a supported naming mode: display, builtin.";
return false;
}
revitParameterNames = parsed;
break;
}
}
}

options = new IfcCliOptions(schema, modelView, preset, configPath, saveConfigPath, noSpaces, showCapabilities);
options = new IfcCliOptions(schema, modelView, preset, configPath, saveConfigPath, noSpaces, showCapabilities,
revitParameterUnits, revitParameterNames);
return true;
}

Expand Down Expand Up @@ -210,8 +240,12 @@ public static bool TryBuildConfiguration(
},
PropertySets = new IfcPropertySetConfiguration
{
ExportRevitPropertySets = revitParameters || revitParameterGroups ? true : null,
ExportRevitPropertySets = revitParameters || revitParameterGroups
|| cliOptions.RevitParameterUnits.HasValue || cliOptions.RevitParameterNames.HasValue
? true : null,
GroupRevitParametersByGroup = revitParameterGroups ? true : null,
RevitParameterUnits = cliOptions.RevitParameterUnits,
RevitParameterNames = cliOptions.RevitParameterNames,
},
};

Expand Down
13 changes: 11 additions & 2 deletions src/RvtIO.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ Diagnostics go to standard error.
--ifc-profile <legacy|current> IFC output profile (default: current)
--ifc-revit-parameters write the Revit parameters as IFC property sets
--ifc-revit-parameter-groups write them as one property set per parameter group (implies --ifc-revit-parameters)
--ifc-revit-parameter-units <ifc|internal>
unit system for Revit parameters: ifc (IFC length/area/volume/angle units and SI
units for other physical specs; implies --ifc-revit-parameters) or internal (default)
--ifc-revit-parameter-names <display|builtin>
property naming for Revit parameters: display (display names with BuiltInParameter
in Description, user parameter names instead of IDs; implies --ifc-revit-parameters)
or builtin (default)
--ifc-no-base-quantities leave out the base quantity sets
--ifc-opening-legacy-axes name the sides of the opening of a door or window by the frame they are measured in (Height
along the wall, Width vertical), as earlier releases did; by default the opening has the Width
Expand Down Expand Up @@ -131,6 +138,8 @@ apply an ordered batch of supported parameter assignments and clears atomically
RvtIO.Cli.IfcConfigurationOptions.PresetOption,
RvtIO.Cli.IfcConfigurationOptions.ConfigOption,
RvtIO.Cli.IfcConfigurationOptions.SaveConfigOption,
RvtIO.Cli.IfcConfigurationOptions.RevitParameterUnitsOption,
RvtIO.Cli.IfcConfigurationOptions.RevitParameterNamesOption,
RvtIO.Cli.IfcLengthUnitOption.Name, RvtIO.Cli.IfcTimestampOption.Name, "--json-class-prefix", "--revit-localization", "--inspect", "--diag-dump", "--find-str",
"--sketch-owner-dump", "--dev-external-dump", "--dev-external-dump-prefix", "--dev-candidates", "--dev-trace", "--dev-facts",
"--dev-fact-names", "--dev-user-params", "--dev-collisions", "--dev-solids", "--dev-native", "--class-census", "--episode-check",
Expand Down Expand Up @@ -388,9 +397,9 @@ static bool IsNonJsonPositionalExtension(string path) =>
Console.Error.WriteLine("--ifc-length-unit requires IFC output.");
return 1;
}
if ((cliIfcOptions.Schema.HasValue || cliIfcOptions.ModelView.HasValue || cliIfcOptions.Preset.HasValue || cliIfcOptions.ConfigPath != null || cliIfcOptions.NoSpaces) && !hasIfcOutput && cliIfcOptions.SaveConfigPath == null)
if ((cliIfcOptions.Schema.HasValue || cliIfcOptions.ModelView.HasValue || cliIfcOptions.Preset.HasValue || cliIfcOptions.ConfigPath != null || cliIfcOptions.NoSpaces || cliIfcOptions.RevitParameterUnits.HasValue || cliIfcOptions.RevitParameterNames.HasValue) && !hasIfcOutput && cliIfcOptions.SaveConfigPath == null)
{
Console.Error.WriteLine("IFC schema, model view, preset, config, and space options require IFC output.");
Console.Error.WriteLine("IFC schema, model view, preset, config, Revit parameter formatting, and space options require IFC output.");
return 1;
}

Expand Down
98 changes: 98 additions & 0 deletions src/RvtIO/Ifc/IfcExportConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ public enum IfcRoomPhaseScope
SpecificPhase,
}

/// <summary>Unit system used when exporting Revit parameters to IFC property sets.</summary>
public enum IfcRevitParameterUnits
{
/// <summary>Preserve Revit internal values as raw reals (feet, radians, etc.).</summary>
Internal,

/// <summary>Convert length, area, volume, and angle parameters to the IFC file units, and other physical spec types to SI units.</summary>
Ifc,
}

/// <summary>Property naming convention used when exporting Revit parameters to IFC property sets.</summary>
public enum IfcRevitParameterNames
{
/// <summary>Use the built-in parameter enum name or stored definition name.</summary>
BuiltIn,

/// <summary>Use each parameter's display name (and place the built-in name in <c>Description</c>).</summary>
Display,
}

/// <summary>Coordinate frame used for opening <c>Width</c> and <c>Height</c> base quantities.</summary>
public enum IfcOpeningQuantityFrame
{
Expand Down Expand Up @@ -282,6 +302,12 @@ public sealed record IfcPropertySetConfiguration
/// <summary>Group Revit parameters into one property set per Revit parameter group (implies <see cref="ExportRevitPropertySets"/>).</summary>
public bool? GroupRevitParametersByGroup { get; init; }

/// <summary>Unit system used when exporting Revit parameters (<c>Internal</c> or <c>Ifc</c>).</summary>
public IfcRevitParameterUnits? RevitParameterUnits { get; init; }

/// <summary>Property naming convention used when exporting Revit parameters (<c>BuiltIn</c> or <c>Display</c>).</summary>
public IfcRevitParameterNames? RevitParameterNames { get; init; }

/// <summary>Export Revit schedules as custom property sets (not implemented; must remain null/false).</summary>
public bool? ExportSchedulesAsPropertySets { get; init; }
}
Expand Down Expand Up @@ -359,6 +385,8 @@ private static JsonSerializerOptions CreateSerializerOptions()
options.Converters.Add(new FlexibleEnumJsonConverter<IfcExportPresetKind>(IfcExportOptionParser.TryParsePreset, IfcExportOptionParser.FormatPreset));
options.Converters.Add(new FlexibleEnumJsonConverter<IfcUnitFamily>(IfcExportOptionParser.TryParseUnitFamily, IfcExportOptionParser.FormatUnitFamily));
options.Converters.Add(new FlexibleEnumJsonConverter<IfcProfile>(IfcExportOptionParser.TryParseProfile, IfcExportOptionParser.FormatProfile));
options.Converters.Add(new FlexibleEnumJsonConverter<IfcRevitParameterUnits>(IfcExportOptionParser.TryParseRevitParameterUnits, IfcExportOptionParser.FormatRevitParameterUnits));
options.Converters.Add(new FlexibleEnumJsonConverter<IfcRevitParameterNames>(IfcExportOptionParser.TryParseRevitParameterNames, IfcExportOptionParser.FormatRevitParameterNames));
options.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, allowIntegerValues: false));
return options;
}
Expand Down Expand Up @@ -561,6 +589,8 @@ public IfcExportConfiguration Merge(IfcExportConfiguration? overrides)
ExportIfcCommonPropertySets = overrides.PropertySets.ExportIfcCommonPropertySets ?? PropertySets.ExportIfcCommonPropertySets,
ExportRevitPropertySets = overrides.PropertySets.ExportRevitPropertySets ?? PropertySets.ExportRevitPropertySets,
GroupRevitParametersByGroup = overrides.PropertySets.GroupRevitParametersByGroup ?? PropertySets.GroupRevitParametersByGroup,
RevitParameterUnits = overrides.PropertySets.RevitParameterUnits ?? PropertySets.RevitParameterUnits,
RevitParameterNames = overrides.PropertySets.RevitParameterNames ?? PropertySets.RevitParameterNames,
ExportSchedulesAsPropertySets = overrides.PropertySets.ExportSchedulesAsPropertySets ?? PropertySets.ExportSchedulesAsPropertySets,
},
Mappings = new IfcMappingConfiguration
Expand Down Expand Up @@ -692,6 +722,16 @@ private ResolvedIfcExportConfiguration ResolveCore(bool throwOnError)
ValidatePhase(effective.Phases, diagnostics);
ValidateUnsupportedFlags(effective, diagnostics);

if (effective.PropertySets.RevitParameterUnits is { } paramUnits && !Enum.IsDefined(paramUnits))
diagnostics.Add(new IfcConfigurationDiagnostic(
"invalid-revit-parameter-units", IfcConfigurationDiagnosticSeverity.Error, "propertySets.revitParameterUnits",
$"Unsupported Revit parameter units '{paramUnits}'. Supported values: Internal, Ifc."));

if (effective.PropertySets.RevitParameterNames is { } paramNames && !Enum.IsDefined(paramNames))
diagnostics.Add(new IfcConfigurationDiagnostic(
"invalid-revit-parameter-names", IfcConfigurationDiagnosticSeverity.Error, "propertySets.revitParameterNames",
$"Unsupported Revit parameter naming '{paramNames}'. Supported values: BuiltIn, Display."));

bool revitGroups = effective.PropertySets.GroupRevitParametersByGroup ?? false;
bool revitPsets = (effective.PropertySets.ExportRevitPropertySets ?? false) || revitGroups;

Expand All @@ -718,6 +758,8 @@ private ResolvedIfcExportConfiguration ResolveCore(bool throwOnError)
ExportIfcCommonPropertySets = effective.PropertySets.ExportIfcCommonPropertySets ?? true,
ExportRevitPropertySets = revitPsets,
RevitParameterGroups = revitGroups,
RevitParameterUnits = effective.PropertySets.RevitParameterUnits,
RevitParameterNames = effective.PropertySets.RevitParameterNames,
RespectExportToIfcParameter = effective.Scope.RespectExportToIfcParameter ?? true,
UseRevitIfcExportAsParameters = effective.Mappings.UseRevitIfcExportAsParameters ?? true,
Diagnostics = diagnostics,
Expand Down Expand Up @@ -860,6 +902,10 @@ public sealed record ResolvedIfcExportConfiguration
public bool ExportRevitPropertySets { get; init; }
/// <summary>True when Revit parameter property sets are grouped per Revit parameter group.</summary>
public bool RevitParameterGroups { get; init; }
/// <summary>Unit conversion mode for exported Revit parameters (<c>null</c> keeps mode default).</summary>
public IfcRevitParameterUnits? RevitParameterUnits { get; init; }
/// <summary>Property naming mode for exported Revit parameters (<c>null</c> keeps mode default).</summary>
public IfcRevitParameterNames? RevitParameterNames { get; init; }
/// <summary>True when the <c>Export to IFC</c> parameter filters elements.</summary>
public bool RespectExportToIfcParameter { get; init; }
/// <summary>True when <c>IfcExportAs</c>/<c>IfcExportType</c> parameters override category mappings.</summary>
Expand Down Expand Up @@ -929,6 +975,12 @@ public static class IfcExportCapabilities
"true, false", "false", "Exports Revit instance and type parameters in IfcPropertySet entities."),
new("propertySets.groupRevitParametersByGroup", "Property Sets", "Group Revit Parameters", IfcCapabilitySupportStatus.Supported,
"true, false", "false", "Splits Revit parameters into one IfcPropertySet per parameter group (implies exportRevitPropertySets)."),
new("propertySets.revitParameterUnits", "Property Sets", "Revit Parameter Units", IfcCapabilitySupportStatus.Supported,
"internal, ifc", "internal (legacy/untyped) / length-area-volume-angle in grouped mode",
"Converts length, area, volume, and angle to IFC file units and other known physical specs to SI units when set to ifc."),
new("propertySets.revitParameterNames", "Property Sets", "Revit Parameter Names", IfcCapabilitySupportStatus.Supported,
"builtin, display", "builtin (or display in grouped mode)",
"Uses display names as property names (preserving BuiltInParameter in Description) and resolves user parameter names when set to display."),
new("propertySets.exportSchedulesAsPropertySets", "Property Sets", "Revit Schedules as Psets", IfcCapabilitySupportStatus.Unsupported,
"false (default)", "false", "Schedule-to-Pset export is not implemented; true fails validation."),
new("mappings.useRevitIfcExportAsParameters", "Mappings", "IfcExportAs / IfcExportType", IfcCapabilitySupportStatus.Supported,
Expand Down Expand Up @@ -1123,6 +1175,52 @@ public static bool TryParseUnitFamily(string? text, out IfcUnitFamily unit)
IfcUnitFamily.Foot => "ft",
_ => unit.ToString(),
};

public static bool TryParseRevitParameterUnits(string? text, out IfcRevitParameterUnits units)
{
switch (text?.Trim().ToLowerInvariant())
{
case "internal":
units = IfcRevitParameterUnits.Internal;
return true;
case "ifc":
units = IfcRevitParameterUnits.Ifc;
return true;
default:
units = default;
return false;
}
}

public static string FormatRevitParameterUnits(IfcRevitParameterUnits units) => units switch
{
IfcRevitParameterUnits.Internal => "internal",
IfcRevitParameterUnits.Ifc => "ifc",
_ => units.ToString(),
};

public static bool TryParseRevitParameterNames(string? text, out IfcRevitParameterNames names)
{
switch (text?.Trim().ToLowerInvariant().Replace("-", ""))
{
case "builtin":
names = IfcRevitParameterNames.BuiltIn;
return true;
case "display":
names = IfcRevitParameterNames.Display;
return true;
default:
names = default;
return false;
}
}

public static string FormatRevitParameterNames(IfcRevitParameterNames names) => names switch
{
IfcRevitParameterNames.BuiltIn => "builtin",
IfcRevitParameterNames.Display => "display",
_ => names.ToString(),
};
}

internal sealed class FlexibleEnumJsonConverter<T> : JsonConverter<T> where T : struct, Enum
Expand Down
Loading
Loading