Skip to content

Add ACadSharp DXF/DWG import/export support  #2

Description

@ChrisClems

netDxf is no longer maintained and is very limited. It currently works by downgrading all imports to ACAD2000/AC1015 format and throws an exception when importing previous versions. ACadSharp is an actively maintained library for DXF manipulation which has full import/export support for text and binary DXFs between R12/AC1012 and ACAD2018/AC1032. It also has DWG support for most versions in the same range. Implementing ACadSharp for DXF/DWG import/export would greatly enhance CADAbility support for AutoCAD files.

This issue will track research into the viability of replacing the DXF import/export functionality in CADability with ACadSharp.

Notes:

  • Does not have native functionality to convert a spline to a polyline, which is relied upon for issue Spline to path FriendsOfCADability/CADability#174 Research alternative fixes based on root cause analysis
  • Support for xData is ongoing. Full support for importing xData from DXF. DWG and export support is in heavy active development as of 2025-1-16.
  • netDxf Text entity export relies on ModOp TransformBy support for DXF entity objects to shortcut text rotation and placement. May take some extra testing to reach feature parity for placing text objects predictably.
  • Uses CSMath.XYZ for coordinate types. netDxf uses custom Vector structs. Math.Numerics.Vector* only supports single floats.
  • Extensive use of System.Drawing.Color in import/export which is no longer a first-class citizen in modern .NET. Should be replaced.
  • netDxf.XDataCode and ACadSharp.DxfCode are enums to the actual DXF spec codes. ACadSharp xData import casts DxfCode to XDataCode to preserve data when exporting data imported from the other importer.
  • Reach feature parity with netDxf importing

    • Line
    • Ray
    • Arc
    • Circle
    • Ellipse
    • Spline
    • Face3D
    • PolyfaceMesh
    • Hatch
    • Solid
    • Insert
    • Polyline2D
    • MLine
    • Text
    • Dimension
    • MText
    • Leader
    • Polyline3D
    • Point
    • Mesh
    • Convert/clean up remaining helper methods and other dependent functionality in ImportDxf.cs.
  • Write tests to compare imported entities for correctness

  • Create DXF containing a comprehensive set of entities for testing

  • Thoroughly test imported entities to verify viability of using ACadSharp for DXF/DWG import

  • Implement more portable color support in CADability ColorDef objects (RGB as bytes in constructor and property?)

  • Revisit all entities in more detail to find optimizations between ACadSharp objects and GeoObjects

    • Line
    • Ray
    • Arc
    • Circle
    • Ellipse
    • Spline
    • Face3D
    • PolyfaceMesh
    • Hatch
    • Solid
    • Insert
    • Polyline2D
      • Implement LW Polyline or 2D polyline as needed based on what was supported in netDxf import
    • MLine
    • Text
    • Dimension
      • Finish implementation (Currently partially implemented from netDxf)
    • MText
      • Implement MText import support (netDxf implementation is broken, current implementation removes newlines)
    • Leader
    • Polyline3D
    • Point
    • Mesh
  • Add version check support for importer

  • Identify any currently unsupported entities which we can implement and add below

  • Write tests for newly supported entities and add to test DXF

  • Reach feature parity with netDxf exporting

    • Point
    • Line
    • Ellipse
    • Polyline
    • BSpline
    • Path
    • Text
      • Fix MText export. Multi-line text is currently producing invalid DXF files which will not open in AutoCAD 2024.
    • Block
    • Face
    • Shell
    • Solid
    • Convert/clean up remaining helper methods and other dependent functionality in ExportDxf.cs.
  • Implement any newly supported entities added to ImportDxf.cs

  • Import test DXF to export a new DXF and compare to original for accuracy

  • Add version selection on export

  • Allow passing optional arbitrary list of ACadSharp entities to Export2() to include in the final result.

  • Revisit all entities in more detail to find optimizations between GeoObjects and ACadSharp entities

    • Point
    • Line
    • Ellipse
    • Polyline
    • BSpline
    • Path
    • Text
    • Block
    • Face
    • Shell
    • Solid
  • Port tested members from ACadSharp version of CADability.Dxf namespace to new class so original legacy functionality can be preserved

Bugs/enhancements addressed during conversion that can be ported back to netDxf:

  • ByBlock attributes are not correctly being set. They must be set on the Insert object which owns the block to apply to the instance.
  • Set transparency of entities using the alpha channel of the ColorDef
  • xData import/export full type checking implemented

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions