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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ jobs:
dotnet-version: |
8.0.x
10.0.x
- run: dotnet build src/DwgIO/DwgIO.csproj -c Release -p:BuildNativeCoreOnly=true --artifacts-path native-core-check
- run: dotnet build src/DwgIO.Scene.Adapter/DwgIO.Scene.Adapter.csproj -c Release -p:BuildNativeCoreOnly=true --artifacts-path native-core-check
- run: dotnet build src/DwgIO.Scene/DwgIO.Scene.csproj -c Release -p:BuildNativeCoreOnly=true --artifacts-path native-core-check
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ API between minor releases.

## [Unreleased]

### Added
- `DwgReaderOptions`: `Strict`, `MaxFileBytes`, `MaxSectionBytes`, `MaxDecompressedBytes`, `MaxObjectCount`,
`ReleaseSectionBuffers`, `Progress` (`IProgress<DwgReadProgress>`), and `DiagnosticOutput` (`TextWriter?`).
- `DwgDocument`: `SourcePath`, `OpenAsync` (path and stream overloads), `ReleaseSectionBuffers()`, `SaveJson` and `ToJson`.
- `DwgExitCodes` public constants matching the CLI exit codes.
- `DwgSceneReader.Read(Stream, ...)` and `DwgSceneOptions.ReadProgress`.
- AutoCAD-style 2D HTML viewer (`--mode 2d`): top-down vector canvas,
Black / Slate / Light themes (`--bg`), adaptive ACI colour 7, grid, UCS icon, crosshair, coordinate readout,
entity search/filter and properties palette. HTML defaults to the IOViewer WebGL 3D export.
- `--unit` support on direct `.obj`, `.glb` and `.html` CLI exports, and input/output collision checks across CLI commands.

### Changed
- Updated package dependencies to `IOScene` `[0.1.2, 0.2.0-0.0)`, `IOScene.Formats` `0.1.0-preview.2` and `IOViewer` `0.4.2`.

## [0.5.0] - 2026-11-20

### Added
Expand Down
8 changes: 5 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ The library is in `src/DwgIO`, the CLI in `src/DwgIO.Cli`, and tests in
`tests/DwgIO.Tests`.

The engine owns DWG reading, its model and the JSON representation of the decoded drawing.
`DwgIO.Scene.Adapter` uses the public API of `DwgIO` and the IOScene contract. OBJ, GLB, SVG and HTML output
live in the existing `DwgIO.Scene` package alongside forwards for the adapter types.
`DwgIO.Scene.Adapter` uses the public API of `DwgIO` and the IOScene contract.
`DwgIO.Scene` keeps the existing scene API and OBJ, GLB, SVG and 3D HTML exporters. The 2D HTML viewer lives in `DwgIO.Cli`.
Output file replacement and export diagnostics belong to the writers.

CI also builds the engine and adapter without the compatibility output code or its dependencies.
CI also builds the engine and scene adapter without the compatibility output code or its dependencies.
Run the compile check with a separate artifact directory.

```sh
dotnet build src/DwgIO/DwgIO.csproj -c Release -p:BuildNativeCoreOnly=true --artifacts-path ./artifacts/native-core-check
dotnet build src/DwgIO.Scene.Adapter/DwgIO.Scene.Adapter.csproj -c Release -p:BuildNativeCoreOnly=true --artifacts-path ./artifacts/native-core-check
dotnet build src/DwgIO.Scene/DwgIO.Scene.csproj -c Release -p:BuildNativeCoreOnly=true --artifacts-path ./artifacts/native-core-check
```

Expand Down
4 changes: 3 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<Deterministic>true</Deterministic>
<DeterministicSourcePaths>true</DeterministicSourcePaths>
<PathMap>$(MSBuildThisFileDirectory.Replace(',', ',,').Replace('=', '=='))=/_/</PathMap>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<PropertyGroup>
<Version>0.5.0</Version>
<Version>0.6.0</Version>
<Authors>mahach666</Authors>
<Copyright>Copyright (c) 2026 IOExtend</Copyright>
<Product>DwgIO</Product>
Expand Down
10 changes: 4 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
</ItemGroup>

<ItemGroup>
<!-- Neutral scene model, referenced by DwgIO.Scene with a range whose upper bound is a prerelease.
IOScene.Formats (GLB and OBJ writers) ships as a preview and needs IOScene 0.1.1 or later. -->
<PackageVersion Include="IOScene" Version="[0.1.1, 0.2.0-0.0)" />
<PackageVersion Include="IOScene.Formats" Version="[0.1.0-preview.1]" />
<!-- Standalone WebGL HTML viewer generator; accepts IOScene scene documents directly. -->
<PackageVersion Include="IOViewer" Version="[0.3.1]" />
<!-- The scene adapter depends on IOScene. The compatibility exporters use IOScene.Formats and IOViewer. -->
<PackageVersion Include="IOScene" Version="[0.1.2, 0.2.0-0.0)" />
<PackageVersion Include="IOScene.Formats" Version="[0.1.0-preview.2]" />
<PackageVersion Include="IOViewer" Version="[0.4.2]" />
</ItemGroup>

<ItemGroup>
Expand Down
29 changes: 12 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ DwgIO is a .NET library and command line tool that reads Autodesk AutoCAD drawin
- Lists the objects of a drawing through its handle map and decodes the geometry of LINE, CIRCLE, ARC and POINT entities.
- Writes a JSON export of the metadata, the section catalog and the decoded entities.
- Converts a drawing into a neutral [IOScene](https://www.nuget.org/packages/IOScene) scene document (`DwgIO.Scene.Adapter` package): geometry in metres, ACI entity colours, one element per entity with its handle.
- Exports the scene to Wavefront OBJ (with an MTL colour library) and binary glTF (GLB).
- Exports the scene to Wavefront OBJ (with an MTL colour library) and binary glTF (GLB) through the CLI.
- Draws model space to SVG (`dwgio svg`): LINE, CIRCLE, ARC and POINT in the top view, in their ACI colours.
- Writes a standalone interactive 3D HTML viewer (`.html`): the WebGL viewer of [IOViewer](https://github.com/IOExtend/IOViewer) embedded with the scene, no server or external scripts.
- Writes a standalone interactive [IOViewer](https://github.com/IOExtend/IOViewer) HTML file. Use `--mode 2d` for the AutoCAD-style top view.

## Install

Expand All @@ -29,12 +29,9 @@ and add the libraries to a .NET project:

```sh
dotnet add package DwgIO
dotnet add package DwgIO.Scene.Adapter
dotnet add package DwgIO.Scene
```

Install `DwgIO.Scene` for the existing scene API with OBJ, GLB, SVG and HTML exporters.
It includes the adapter.

The libraries target .NET 8 and .NET 10. They use managed code without native dependencies or Windows-only APIs and support Windows, Linux and macOS. Tests run on Windows, Linux and macOS.

## Command line
Expand Down Expand Up @@ -69,11 +66,11 @@ Export a neutral IOScene scene document (geometry in metres, ACI colours, one el
dwgio scene drawing.dwg drawing.scene.json --unit mm
```

The plain export command writes OBJ and GLB by output extension, through the same scene:
The plain export command writes OBJ, GLB and HTML by output extension (with `--unit mm|cm|m|ft|in`):

```sh
dwgio drawing.dwg drawing.obj # Wavefront OBJ + drawing.mtl with the ACI colours
dwgio drawing.dwg drawing.glb # binary glTF for viewers and web scenes
dwgio drawing.dwg drawing.obj --unit mm # Wavefront OBJ + drawing.mtl with the ACI colours
dwgio drawing.dwg drawing.glb --unit mm # binary glTF for viewers and web scenes
```

Draw model space to SVG (X to the right, Y up, ACI colours; `--scale` sets pixels per drawing unit):
Expand All @@ -82,10 +79,12 @@ Draw model space to SVG (X to the right, Y up, ACI colours; `--scale` sets pixel
dwgio svg drawing.dwg drawing.svg --scale 2
```

Open the drawing in a standalone interactive 3D HTML viewer:
Open the drawing in the standalone 3D viewer, or choose the AutoCAD-style top view with `--mode 2d`:

```sh
dwgio drawing.dwg drawing.html
dwgio drawing.dwg drawing-slate.html --mode 2d --bg slate
dwgio drawing.dwg drawing-3d.html --mode 3d
```

List the decoded entities, one line each, optionally filtered by type and as JSON:
Expand Down Expand Up @@ -147,7 +146,7 @@ foreach (var entity in doc.Entities)
The JSON export is `DwgJsonExporter` in the `DwgIO.Json` namespace. See [Getting started](docs/getting-started.md) and [Public API](docs/public-api.md) for the supported types.

`DwgSceneReader` converts a drawing into an `IOScene.SceneDocument`, the neutral model shared with RvtIO and NwcIO.
The converter is available in `DwgIO.Scene.Adapter` and through the existing `DwgIO.Scene` API.
Install `DwgIO.Scene.Adapter` for conversion or `DwgIO.Scene` for conversion and the existing export APIs.

```csharp
using DwgIO.Scene;
Expand All @@ -158,8 +157,6 @@ IOScene.SceneJson.Save(scene.Document, "drawing.scene.json");

Every coordinate is scaled to metres by `LengthUnit` (a DWG stores plain numbers, so the unit is a caller decision and `UnitAssumed` records it), each entity becomes an element with its handle as `SourceId`, and LINE, CIRCLE, ARC and POINT become line and point geometries with their ACI colour.

`DwgSceneExport` writes that scene out in the exchange formats: `SaveObj(document, "drawing.obj", options)` produces an OBJ with an adjacent MTL colour library (with rollback if replacement fails), `SaveGlb(document, "drawing.glb", options)` produces binary glTF. Both return the same `DwgSceneResult` report.

The documentation site with the API reference is at <https://ioextend.github.io/DwgIO/>. [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/IOExtend/DwgIO) offers an automatically generated overview of the repository.

## Status
Expand All @@ -175,10 +172,8 @@ The documentation site with the API reference is at <https://ioextend.github.io/
| `AcDb:AppInfo`, `AcDb:FileDepList` and `AcDb:Preview` parsing | done |
| Handle map and object stream inventory | done |
| Entity decoding: LINE, CIRCLE, ARC and POINT geometry | done (partial) |
| IOScene scene conversion (`DwgIO.Scene.Adapter`): entities, geometry, ACI colours | done (partial) |
| OBJ and GLB export through the scene | done (partial) |
| SVG export of model space (`dwgio svg`) | done (partial) |
| Standalone HTML viewer export through IOViewer | done (partial) |
| IOScene scene conversion (`DwgIO.Scene`): entities, geometry, ACI colours | done (partial) |
| OBJ, GLB, SVG and standalone 2D/3D HTML viewer export (`DwgIO.Cli`) | done (partial) |
| AutoCAD 2007 container (AC1021) | planned |
| R13 to R2000 container (AC1012 to AC1015) | planned |

Expand Down
4 changes: 3 additions & 1 deletion docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"metadata": [
{
"src": [
{ "src": "src/DwgIO", "files": ["DwgIO.csproj"] }
{ "src": "src/DwgIO", "files": ["DwgIO.csproj"] },
{ "src": "src/DwgIO.Scene.Adapter", "files": ["DwgIO.Scene.Adapter.csproj"] },
{ "src": "src/DwgIO.Scene", "files": ["DwgIO.Scene.csproj"] }
],
"dest": "docs/api",
"properties": { "TargetFramework": "net10.0" },
Expand Down
45 changes: 21 additions & 24 deletions docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ change in any release and is visible only to the test project through `Internals

| Type | Use |
|---|---|
| `DwgDocument` | Opens a drawing (`Open(path, options?)` or `Open(stream, documentName?, options?)`) and gives its version, file and container headers, section catalog, metadata, handle map, object inventory, entities and `Diagnostics`. `ReadSection(name)` returns the decompressed bytes of one named section. |
| `DwgReaderOptions` | What `Open` reads: `ReadSectionMap`, `ReadSummaryInfo`, `ReadMetadata`, `ReadObjects`, `ReadEntities` (all on by default) and `VerifyChecksums` (off by default). |
| `DwgException` | Thrown for a damaged or truncated file, and by `ReadSection` for an unknown section name, a document opened without its section map, or a checksum mismatch when `VerifyChecksums` is on. |
| `DwgDocument` | Opens a drawing (`Open` / `OpenAsync` from path or stream) and gives `SourcePath` (null for streams), `Path`, `Version`, file and container headers, section catalog, metadata, handle map, object inventory, entities and `Diagnostics`. `ReadSection(name)` returns decompressed section bytes; `ReleaseSectionBuffers()` drops retained raw buffers; `SaveJson` / `ToJson` write JSON. |
| `DwgReaderOptions` | What `Open` reads and enforces: `ReadSectionMap`, `ReadSummaryInfo`, `ReadMetadata`, `ReadObjects`, `ReadEntities`, `VerifyChecksums`, `Strict` (throws on diagnostics), `ReleaseSectionBuffers`, `MaxFileBytes`, `MaxSectionBytes`, `MaxDecompressedBytes`, `MaxObjectCount`, `Progress` and `DiagnosticOutput`. |
| `DwgReadProgress` | Synchronous phase updates (`Phase`, `Completed`, `Total`) delivered via `DwgReaderOptions.Progress`. |
| `DwgExitCodes` | Standard CLI exit codes (`Ok = 0`, `Usage = 1`, `FileNotFound = 2`, `UnsupportedVersion = 3`, `ParseError = 4`, `NoPreview = 5`). |
| `DwgException` | Thrown for a damaged or truncated file, exceeded reader limits, `Strict` diagnostic failures, and by `ReadSection` when buffers were released or a section is missing. |
| `DwgUnsupportedVersionException` | Thrown when the version is not recognised or its container is not implemented yet (R13 to R2000, R2007). Derives from `DwgException`. |

`DwgDocument.Open` throws `FileNotFoundException` when the file does not exist.
Expand Down Expand Up @@ -60,24 +62,18 @@ and `objects`, the numbers `pageCount` and `entityCount`, the `entities` array a
out. In `objects`, `byType` keeps hexadecimal keys and `byTypeName` gives the same counts by readable name.
For `appInfoHistory`, the export reports the byte size. Section bytes can be embedded with `IncludeSectionContents`.

## Scene conversion and export
## Scene conversion (`DwgIO.Scene`)

Install `DwgIO.Scene.Adapter` to turn a drawing into a neutral [IOScene](https://www.nuget.org/packages/IOScene)
scene document. The adapter depends on the matching `DwgIO` version and IOScene. It produces one model per drawing
and one element per decoded entity, with its handle as `SourceId`, line and point geometry in metres,
ACI colours on placements and a report in `DwgSceneResult.Diagnostics`.

The existing `DwgIO.Scene` package includes the adapter and provides the OBJ, GLB, SVG and HTML exporters.
Both packages expose the conversion API in the `DwgIO.Scene` namespace.
scene document. The adapter depends on `DwgIO` and `IOScene`. `DwgIO.Scene` includes the adapter and the existing exporter APIs.
It produces one model per drawing and one element per decoded entity, with its handle as `SourceId`,
line and point geometry in metres, ACI colours on placements and a report in `DwgSceneResult.Diagnostics`.

| Type | Use |
|---|---|
| `DwgSceneReader` | `Read(path, options?)` opens and converts a drawing file; `Read(document, options)` converts an already opened `DwgDocument` (which needs `ModelKey`, because a document from memory has no file name). |
| `DwgSceneOptions` | `LengthUnit` (one of `mm`, `cm`, `m`, `ft`, `in`; default `m` — a DWG names no unit, so the caller chooses) and `ModelKey`. |
| `DwgSceneReader` | `Read(path, options?)` opens and converts a drawing file (releasing raw section buffers automatically); `Read(stream, documentName?, options?)` converts a drawing from a stream; `Read(document, options)` converts an already opened `DwgDocument` (which needs `ModelKey`). |
| `DwgSceneOptions` | `LengthUnit` (`mm`, `cm`, `m`, `ft`, `in`; default `m`), `ModelKey`, and `ReadProgress` (`IProgress<DwgReadProgress>?`). |
| `DwgSceneResult` | The `Document` (an `IOScene.SceneDocument`), `Diagnostics`, element and geometry counters, the applied `MetresPerUnit` and `UnitAssumed`. |
| `DwgSceneExport` | `SaveObj(document, objPath, options?)` writes an OBJ file with an adjacent MTL colour library; `SaveGlb(document, glbPath, options?)` writes binary glTF. Both return the conversion report; `WriteObj(scene, path)` and `WriteGlb(scene, path)` export an existing scene document. |
| `DwgSvgExporter`, `DwgSvgOptions` | Draws model space (LINE, CIRCLE, ARC, POINT) to SVG in the top view, in ACI colours, with a view box that contains every drawn entity. `WriteFile(document, path, options?)`, `Write(document, stream, options?)`. `DwgSvgOptions` holds `Scale` (pixels per drawing unit), `StrokeWidth`, `Background` and an optional `ReportDiagnostic` callback for skipped entities. |
| `DwgViewerExport` | `SaveViewer(document, htmlPath, options?, viewerOptions?)` writes a standalone interactive 3D HTML viewer (IOViewer) of the scene; `WriteViewer(scene, path, viewerOptions?)` embeds an existing scene document. |

```csharp
using DwgIO.Scene;
Expand All @@ -87,15 +83,16 @@ IOScene.SceneJson.Save(result.Document, "drawing.scene.json");
```

The scene validates against the IOScene contract (`SceneDocument.Validate` reports no error) and round-trips through
IOScene JSON with its original line and point topology. Use `dwgio scene drawing.dwg drawing.scene.json --unit mm`
for a millimetre drawing when the consumer supports that topology. `DwgSceneExport` also preserves lines and points
when writing OBJ (with an adjacent MTL colour library) or GLB through the IOScene.Formats writers.

For standalone HTML, use `dwgio drawing.dwg drawing.html` or `DwgViewerExport.SaveViewer`. DwgIO turns lines and
points into display-only triangle meshes without changing the source scene. In contrast, passing the raw scene
JSON to stock `ioviewer drawing.scene.json -o drawing.html` in IOViewer 0.3.1 warns about and skips non-triangle
instances. For example, on LibreDWG's [R2010 example drawing][dwg-example], DwgIO 0.5.0 exported 74 line and 46 point
instances. IOViewer 0.3.1 embedded no drawable instances from that JSON, while direct DwgIO HTML included all 120.
IOScene JSON with its original line and point topology.

## CLI Exporters (`dwgio`)

`DwgIO.Scene` provides `DwgSceneExport` for OBJ/GLB, `DwgSvgExporter` for SVG and `DwgViewerExport` for standalone 3D HTML.
The CLI uses these exporters and adds a 2D HTML viewer:

- `dwgio drawing.dwg drawing.html` exports the interactive 3D WebGL viewer via [IOViewer](https://github.com/IOExtend/IOViewer). You can also pass `--mode 3d`.
- `dwgio drawing.dwg drawing.html --mode 2d` exports an AutoCAD-style top view. Use `--bg black|slate|light` to set its background.
- `dwgio drawing.dwg out.obj --unit mm` and `dwgio drawing.dwg out.glb --unit mm` pass `--unit` to the scene converter.

## Diagnostics

Expand Down
7 changes: 5 additions & 2 deletions src/DwgIO.Cli/DwgIO.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<PackAsTool>true</PackAsTool>
<ToolCommandName>dwgio</ToolCommandName>
<PackageId>DwgIO.Cli</PackageId>
<Description>Command line tool that reads Autodesk DWG drawings (.dwg) without AutoCAD and writes JSON.</Description>
<Description>Command line tool that reads Autodesk DWG drawings (.dwg) without AutoCAD and exports JSON, IOScene, OBJ, GLB, SVG and standalone HTML viewers.</Description>
<NoWarn>$(NoWarn);NU5104</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand All @@ -15,7 +16,9 @@
</ItemGroup>

<ItemGroup>
<Compile Include="..\Shared\AtomicOutput.cs" Link="AtomicOutput.cs" />
<PackageReference Include="IOViewer" />
<Compile Include="..\Shared\AtomicOutput.cs;..\Shared\ArcAngles.cs;..\Shared\DwgAciPalette.cs"
Link="Shared\%(Filename)%(Extension)" />
<InternalsVisibleTo Include="DwgIO.Tests" />
</ItemGroup>

Expand Down
Loading
Loading