Class DxfDocument
Represents a document to read and write DXF files.
Inherited Members
Namespace: netDxf
Assembly: CADability.dll
Syntax
public sealed class DxfDocument : DxfObject
Constructors
| Improve this Doc View SourceDxfDocument()
Initializes a new instance of the DxfDocument class.
Declaration
public DxfDocument()
Remarks
The default HeaderVariables of the document will be used.
DxfDocument(DxfVersion)
Initializes a new instance of the DxfDocument class.
Declaration
public DxfDocument(DxfVersion version)
Parameters
| Type | Name | Description |
|---|---|---|
| DxfVersion | version | AutoCAD drawing database version number. |
DxfDocument(DxfVersion, IEnumerable<String>)
Initializes a new instance of the DxfDocument class.
Declaration
public DxfDocument(DxfVersion version, IEnumerable<string> supportFolders)
Parameters
| Type | Name | Description |
|---|---|---|
| DxfVersion | version | AutoCAD drawing database version number. |
| System.Collections.Generic.IEnumerable<System.String> | supportFolders | List of the document support folders. |
DxfDocument(HeaderVariables)
Initializes a new instance of the DxfDocument class.
Declaration
public DxfDocument(HeaderVariables drawingVariables)
Parameters
| Type | Name | Description |
|---|---|---|
| HeaderVariables | drawingVariables | HeaderVariables of the document. |
DxfDocument(HeaderVariables, IEnumerable<String>)
Initializes a new instance of the DxfDocument class.
Declaration
public DxfDocument(HeaderVariables drawingVariables, IEnumerable<string> supportFolders)
Parameters
| Type | Name | Description |
|---|---|---|
| HeaderVariables | drawingVariables | HeaderVariables of the document. |
| System.Collections.Generic.IEnumerable<System.String> | supportFolders | List of the document support folders. |
DxfDocument(IEnumerable<String>)
Initializes a new instance of the DxfDocument class.
Declaration
public DxfDocument(IEnumerable<string> supportFolders)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<System.String> | supportFolders | List of the document support folders. |
Remarks
The default HeaderVariables of the document will be used.
Properties
| Improve this Doc View SourceActiveLayout
Gets or sets the name of the active layout.
Declaration
public string ActiveLayout { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
ApplicationRegistries
Gets the ApplicationRegistries collection.
Declaration
public ApplicationRegistries ApplicationRegistries { get; }
Property Value
| Type | Description |
|---|---|
| ApplicationRegistries |
Arcs
Gets the Arc list contained in the active layout.
Declaration
public IEnumerable<Arc> Arcs { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Arc> |
AttributeDefinitions
Gets the AttributeDefinition list in the active layout.
Declaration
public IEnumerable<AttributeDefinition> AttributeDefinitions { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<AttributeDefinition> |
Blocks
Gets the BlockRecords collection.
Declaration
public BlockRecords Blocks { get; }
Property Value
| Type | Description |
|---|---|
| BlockRecords |
BuildDimensionBlocks
Declaration
public bool BuildDimensionBlocks { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Remarks
By default this value is set to false, no dimension blocks will be generated when adding dimension entities to the document.
It will be the responsibility of the program importing the DXF to generate the drawing that represent the dimensions.
When set to true the block that represents the dimension will be generated,
keep in mind that this process is limited and not all options available in the dimension style will be reflected in the final result.
When importing a file if the dimension block is present it will be read, regardless of this value.
If, later, the dimension is modified all updates will be done with the limited dimension drawing capabilities of the library,
in this case, if you want that the new modifications to be reflected when the file is saved again you can set the dimension block to null,
and the program reading the resulting file will regenerate the block with the new modifications.
Circles
Gets the Circle list in the active layout.
Declaration
public IEnumerable<Circle> Circles { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Circle> |
Comments
Gets or sets the name of the document, once a file is saved or loaded this field is equals the file name without extension.
Declaration
public List<string> Comments { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<System.String> |
Dimensions
Gets the Dimension list in the active layout.
Declaration
public IEnumerable<Dimension> Dimensions { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Dimension> |
DimensionStyles
Gets the DimensionStyles collection.
Declaration
public DimensionStyles DimensionStyles { get; }
Property Value
| Type | Description |
|---|---|
| DimensionStyles |
DrawingVariables
Gets the DXF HeaderVariables.
Declaration
public HeaderVariables DrawingVariables { get; }
Property Value
| Type | Description |
|---|---|
| HeaderVariables |
Ellipses
Gets the Ellipse list in the active layout.
Declaration
public IEnumerable<Ellipse> Ellipses { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Ellipse> |
Faces3d
Gets the Face3d list in the active layout.
Declaration
public IEnumerable<Face3d> Faces3d { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Face3d> |
Groups
Gets the Groups collection.
Declaration
public Groups Groups { get; }
Property Value
| Type | Description |
|---|---|
| Groups |
Hatches
Gets the Hatch list in the active layout.
Declaration
public IEnumerable<Hatch> Hatches { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Hatch> |
ImageDefinitions
Gets the ImageDefinitions collection.
Declaration
public ImageDefinitions ImageDefinitions { get; }
Property Value
| Type | Description |
|---|---|
| ImageDefinitions |
Images
Gets the Image list in the active layout.
Declaration
public IEnumerable<Image> Images { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Image> |
Inserts
Gets the Insert list in the active layout.
Declaration
public IEnumerable<Insert> Inserts { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Insert> |
Layers
Gets the Layers collection.
Declaration
public Layers Layers { get; }
Property Value
| Type | Description |
|---|---|
| Layers |
Layouts
Gets the Layouts collection.
Declaration
public Layouts Layouts { get; }
Property Value
| Type | Description |
|---|---|
| Layouts |
Leaders
Gets the Leader list in the active layout.
Declaration
public IEnumerable<Leader> Leaders { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Leader> |
Lines
Gets the Line list in the active layout.
Declaration
public IEnumerable<Line> Lines { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Line> |
Linetypes
Gets the Linetypes collection.
Declaration
public Linetypes Linetypes { get; }
Property Value
| Type | Description |
|---|---|
| Linetypes |
LwPolylines
Gets the LwPolyline list in the active layout.
Declaration
public IEnumerable<LwPolyline> LwPolylines { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<LwPolyline> |
Meshes
Gets the Mesh list in the active layout.
Declaration
public IEnumerable<Mesh> Meshes { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Mesh> |
MLines
Gets the MLine list in the active layout.
Declaration
public IEnumerable<MLine> MLines { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<MLine> |
MlineStyles
Gets the MLineStyles collection.
Declaration
public MLineStyles MlineStyles { get; }
Property Value
| Type | Description |
|---|---|
| MLineStyles |
MTexts
Gets the MText list in the active layout.
Declaration
public IEnumerable<MText> MTexts { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<MText> |
Name
Gets or sets the name of the document.
Declaration
public string Name { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
Remarks
When a file is loaded this field is equals the file name without extension.
Points
Gets the Point list in the active layout.
Declaration
public IEnumerable<Point> Points { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Point> |
PolyfaceMeshes
Gets the PolyfaceMeshes list in the active layout.
Declaration
public IEnumerable<PolyfaceMesh> PolyfaceMeshes { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<PolyfaceMesh> |
Polylines
Gets the Polyline list in the active layout.
Declaration
public IEnumerable<Polyline> Polylines { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Polyline> |
RasterVariables
Gets or sets the RasterVariables applied to image entities.
Declaration
public RasterVariables RasterVariables { get; set; }
Property Value
| Type | Description |
|---|---|
| RasterVariables |
Rays
Gets the Ray list in the active layout.
Declaration
public IEnumerable<Ray> Rays { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Ray> |
Shapes
Gets the Shape list in the active layout.
Declaration
public IEnumerable<Shape> Shapes { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Shape> |
ShapeStyles
Gets the ShapeStyles collection.
Declaration
public ShapeStyles ShapeStyles { get; }
Property Value
| Type | Description |
|---|---|
| ShapeStyles |
Remarks
The DXF stores the TextStyles and ShapeStyles in the same table list, here, they are separated since they serve a different role. Under normal circumstances you should not need to access this list.
Solids
Gets the Solid list in the active layout.
Declaration
public IEnumerable<Solid> Solids { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Solid> |
Splines
Gets the Spline list in the active layout.
Declaration
public IEnumerable<Spline> Splines { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Spline> |
SupportFolders
Gets the list of folders where the drawing support files are present.
Declaration
public SupportFolders SupportFolders { get; }
Property Value
| Type | Description |
|---|---|
| SupportFolders |
Remarks
When shape linetype segments are used, the shape number will be obtained reading the .shp file equivalent to the .shx file, that file will be looked for in the same folder as the .shx file or one of the document support folders.
Texts
Gets the Text list in the active layout.
Declaration
public IEnumerable<Text> Texts { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Text> |
TextStyles
Gets the TextStyles collection.
Declaration
public TextStyles TextStyles { get; }
Property Value
| Type | Description |
|---|---|
| TextStyles |
Tolerances
Gets the Tolerance list in the active layout.
Declaration
public IEnumerable<Tolerance> Tolerances { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Tolerance> |
Traces
Gets the Trace list in the active layout.
Declaration
public IEnumerable<Trace> Traces { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Trace> |
UCSs
Gets the UCSs collection.
Declaration
public UCSs UCSs { get; }
Property Value
| Type | Description |
|---|---|
| UCSs |
UnderlayDgnDefinitions
Gets the UnderlayDgnDefinitions collection.
Declaration
public UnderlayDgnDefinitions UnderlayDgnDefinitions { get; }
Property Value
| Type | Description |
|---|---|
| UnderlayDgnDefinitions |
UnderlayDwfDefinitions
Gets the UnderlayDwfDefinitions collection.
Declaration
public UnderlayDwfDefinitions UnderlayDwfDefinitions { get; }
Property Value
| Type | Description |
|---|---|
| UnderlayDwfDefinitions |
UnderlayPdfDefinitions
Gets the UnderlayPdfDefinitions collection.
Declaration
public UnderlayPdfDefinitions UnderlayPdfDefinitions { get; }
Property Value
| Type | Description |
|---|---|
| UnderlayPdfDefinitions |
Underlays
Gets the Underlay list in the active layout.
Declaration
public IEnumerable<Underlay> Underlays { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Underlay> |
Viewport
Gets the document viewport.
Declaration
public VPort Viewport { get; }
Property Value
| Type | Description |
|---|---|
| VPort |
Remarks
This is the same as the *Active VPort in the VPorts list, it describes the current viewport.
Viewports
Gets the Viewport list in the active layout.
Declaration
public IEnumerable<Viewport> Viewports { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Viewport> |
VPorts
Gets the VPorts collection.
Declaration
public VPorts VPorts { get; }
Property Value
| Type | Description |
|---|---|
| VPorts |
Wipeouts
Gets the Wipeout list in the active layout.
Declaration
public IEnumerable<Wipeout> Wipeouts { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<Wipeout> |
XLines
Gets the XLine list in the active layout.
Declaration
public IEnumerable<XLine> XLines { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<XLine> |
Methods
| Improve this Doc View SourceAddEntity(EntityObject)
Adds an EntityObject to the document.
Declaration
public void AddEntity(EntityObject entity)
Parameters
| Type | Name | Description |
|---|---|---|
| EntityObject | entity | An EntityObject to add to the document. |
AddEntity(IEnumerable<EntityObject>)
Adds a list of EntityObject to the document.
Declaration
public void AddEntity(IEnumerable<EntityObject> entities)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<EntityObject> | entities | A list of EntityObject to add to the document. |
CheckDxfFileVersion(Stream)
Checks the AutoCAD DXF file database version.
Declaration
public static DxfVersion CheckDxfFileVersion(Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | stream | Stream |
Returns
| Type | Description |
|---|---|
| DxfVersion | String that represents the DXF file version. |
Remarks
The caller will be responsible of closing the stream.
CheckDxfFileVersion(Stream, out Boolean)
Checks the AutoCAD DXF file database version.
Declaration
public static DxfVersion CheckDxfFileVersion(Stream stream, out bool isBinary)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | stream | Stream |
| System.Boolean | isBinary | Returns true if the DXF is a binary file. |
Returns
| Type | Description |
|---|---|
| DxfVersion | String that represents the DXF file version. |
Remarks
The caller will be responsible of closing the stream.
CheckDxfFileVersion(String)
Checks the AutoCAD DXF file database version.
Declaration
public static DxfVersion CheckDxfFileVersion(string file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | File name. |
Returns
| Type | Description |
|---|---|
| DxfVersion | String that represents the DXF file version. |
CheckDxfFileVersion(String, out Boolean)
Checks the AutoCAD DXF file database version.
Declaration
public static DxfVersion CheckDxfFileVersion(string file, out bool isBinary)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | File name. |
| System.Boolean | isBinary | Returns true if the DXF is a binary file. |
Returns
| Type | Description |
|---|---|
| DxfVersion | String that represents the DXF file version. |
GetObjectByHandle(String)
Gets a DXF object by its handle.
Declaration
public DxfObject GetObjectByHandle(string objectHandle)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | objectHandle | DxfObject handle. |
Returns
| Type | Description |
|---|---|
| DxfObject | The DxfObject that has the provided handle, null otherwise. |
Load(Stream)
Loads a DXF file.
Declaration
public static DxfDocument Load(Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | stream | Stream. |
Returns
| Type | Description |
|---|---|
| DxfDocument | Returns a DxfDocument. It will return null if the file has not been able to load. |
Remarks
Loading DXF files prior to AutoCad 2000 is not supported.
On Debug mode it will raise any exception that might occur during the whole process.
The caller will be responsible of closing the stream.
Exceptions
| Type | Condition |
|---|---|
| DxfVersionNotSupportedException |
Load(Stream, IEnumerable<String>)
Loads a DXF file.
Declaration
public static DxfDocument Load(Stream stream, IEnumerable<string> supportFolders)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | stream | Stream. |
| System.Collections.Generic.IEnumerable<System.String> | supportFolders | List of the document support folders. |
Returns
| Type | Description |
|---|---|
| DxfDocument | Returns a DxfDocument. It will return null if the file has not been able to load. |
Remarks
Loading DXF files prior to AutoCad 2000 is not supported.
On Debug mode it will raise any exception that might occur during the whole process.
The caller will be responsible of closing the stream.
Exceptions
| Type | Condition |
|---|---|
| DxfVersionNotSupportedException |
Load(String)
Loads a DXF file.
Declaration
public static DxfDocument Load(string file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | File name. |
Returns
| Type | Description |
|---|---|
| DxfDocument | Returns a DxfDocument. It will return null if the file has not been able to load. |
Remarks
Loading DXF files prior to AutoCad 2000 is not supported.
The Load method will still raise an exception if they are unable to create the FileStream.
On Debug mode it will raise any exception that might occur during the whole process.
Exceptions
| Type | Condition |
|---|---|
| DxfVersionNotSupportedException |
Load(String, IEnumerable<String>)
Loads a DXF file.
Declaration
public static DxfDocument Load(string file, IEnumerable<string> supportFolders)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | File name. |
| System.Collections.Generic.IEnumerable<System.String> | supportFolders | List of the document support folders. |
Returns
| Type | Description |
|---|---|
| DxfDocument | Returns a DxfDocument. It will return null if the file has not been able to load. |
Remarks
Loading DXF files prior to AutoCad 2000 is not supported.
The Load method will still raise an exception if they are unable to create the FileStream.
On Debug mode it will raise any exception that might occur during the whole process.
Exceptions
| Type | Condition |
|---|---|
| DxfVersionNotSupportedException |
RemoveEntity(EntityObject)
Removes an EntityObject from the document.
Declaration
public bool RemoveEntity(EntityObject entity)
Parameters
| Type | Name | Description |
|---|---|---|
| EntityObject | entity | The EntityObject to remove from the document. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if item is successfully removed; otherwise, false. This method also returns false if item was not found. |
Remarks
This function will not remove other tables objects that might be not in use as result from the elimination of the entity.
This includes empty layers, blocks not referenced anymore, line types, text styles, dimension styles, multiline styles, groups, and application registries.
Entities that are part of a block definition will not be removed.
RemoveEntity(IEnumerable<EntityObject>)
Removes a list of EntityObject from the document.
Declaration
public void RemoveEntity(IEnumerable<EntityObject> entities)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<EntityObject> | entities | A list of EntityObject to remove from the document. |
Remarks
This function will not remove other tables objects that might be not in use as result from the elimination of the entity.
This includes empty layers, blocks not referenced anymore, line types, text styles, dimension styles, and application registries.
Entities that are part of a block definition will not be removed.
Save(Stream)
Saves the database of the actual DxfDocument to a text stream.
Declaration
public bool Save(Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | stream | Stream. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Return true if the stream has been successfully saved, false otherwise. |
Remarks
On Debug mode it will raise any exception that might occur during the whole process.
The caller will be responsible of closing the stream.
Exceptions
| Type | Condition |
|---|---|
| DxfVersionNotSupportedException |
Save(Stream, Boolean)
Saves the database of the actual DxfDocument to a stream.
Declaration
public bool Save(Stream stream, bool isBinary)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | stream | Stream. |
| System.Boolean | isBinary | Defines if the file will be saved as binary. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Return true if the stream has been successfully saved, false otherwise. |
Remarks
On Debug mode it will raise any exception that might occur during the whole process.
The caller will be responsible of closing the stream.
Exceptions
| Type | Condition |
|---|---|
| DxfVersionNotSupportedException |
Save(String)
Saves the database of the actual DxfDocument to a text DXF file.
Declaration
public bool Save(string file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | File name. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Return true if the file has been successfully save, false otherwise. |
Remarks
If the file already exists it will be overwritten.
The Save method will still raise an exception if they are unable to create the FileStream.
On Debug mode they will raise any exception that might occur during the whole process.
Exceptions
| Type | Condition |
|---|---|
| DxfVersionNotSupportedException |
Save(String, Boolean)
Saves the database of the actual DxfDocument to a DXF file.
Declaration
public bool Save(string file, bool isBinary)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | File name. |
| System.Boolean | isBinary | Defines if the file will be saved as binary. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Return true if the file has been successfully save, false otherwise. |
Remarks
If the file already exists it will be overwritten.
The Save method will still raise an exception if they are unable to create the FileStream.
On Debug mode they will raise any exception that might occur during the whole process.
Exceptions
| Type | Condition |
|---|---|
| DxfVersionNotSupportedException |