Show / Hide Table of Contents

Class DxfDocument

Represents a document to read and write DXF files.

Inheritance
System.Object
DxfObject
DxfDocument
Inherited Members
DxfObject.CodeName
DxfObject.Handle
DxfObject.Owner
DxfObject.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: netDxf
Assembly: CADability.dll
Syntax
public sealed class DxfDocument : DxfObject

Constructors

| Improve this Doc View Source

DxfDocument()

Initializes a new instance of the DxfDocument class.

Declaration
public DxfDocument()
Remarks

The default HeaderVariables of the document will be used.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 Source

ActiveLayout

Gets or sets the name of the active layout.

Declaration
public string ActiveLayout { get; set; }
Property Value
Type Description
System.String
| Improve this Doc View Source

ApplicationRegistries

Gets the ApplicationRegistries collection.

Declaration
public ApplicationRegistries ApplicationRegistries { get; }
Property Value
Type Description
ApplicationRegistries
| Improve this Doc View Source

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>
| Improve this Doc View Source

AttributeDefinitions

Gets the AttributeDefinition list in the active layout.

Declaration
public IEnumerable<AttributeDefinition> AttributeDefinitions { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<AttributeDefinition>
| Improve this Doc View Source

Blocks

Gets the BlockRecords collection.

Declaration
public BlockRecords Blocks { get; }
Property Value
Type Description
BlockRecords
| Improve this Doc View Source

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.

| Improve this Doc View Source

Circles

Gets the Circle list in the active layout.

Declaration
public IEnumerable<Circle> Circles { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Circle>
| Improve this Doc View Source

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>
| Improve this Doc View Source

Dimensions

Gets the Dimension list in the active layout.

Declaration
public IEnumerable<Dimension> Dimensions { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Dimension>
| Improve this Doc View Source

DimensionStyles

Gets the DimensionStyles collection.

Declaration
public DimensionStyles DimensionStyles { get; }
Property Value
Type Description
DimensionStyles
| Improve this Doc View Source

DrawingVariables

Gets the DXF HeaderVariables.

Declaration
public HeaderVariables DrawingVariables { get; }
Property Value
Type Description
HeaderVariables
| Improve this Doc View Source

Ellipses

Gets the Ellipse list in the active layout.

Declaration
public IEnumerable<Ellipse> Ellipses { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Ellipse>
| Improve this Doc View Source

Faces3d

Gets the Face3d list in the active layout.

Declaration
public IEnumerable<Face3d> Faces3d { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Face3d>
| Improve this Doc View Source

Groups

Gets the Groups collection.

Declaration
public Groups Groups { get; }
Property Value
Type Description
Groups
| Improve this Doc View Source

Hatches

Gets the Hatch list in the active layout.

Declaration
public IEnumerable<Hatch> Hatches { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Hatch>
| Improve this Doc View Source

ImageDefinitions

Gets the ImageDefinitions collection.

Declaration
public ImageDefinitions ImageDefinitions { get; }
Property Value
Type Description
ImageDefinitions
| Improve this Doc View Source

Images

Gets the Image list in the active layout.

Declaration
public IEnumerable<Image> Images { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Image>
| Improve this Doc View Source

Inserts

Gets the Insert list in the active layout.

Declaration
public IEnumerable<Insert> Inserts { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Insert>
| Improve this Doc View Source

Layers

Gets the Layers collection.

Declaration
public Layers Layers { get; }
Property Value
Type Description
Layers
| Improve this Doc View Source

Layouts

Gets the Layouts collection.

Declaration
public Layouts Layouts { get; }
Property Value
Type Description
Layouts
| Improve this Doc View Source

Leaders

Gets the Leader list in the active layout.

Declaration
public IEnumerable<Leader> Leaders { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Leader>
| Improve this Doc View Source

Lines

Gets the Line list in the active layout.

Declaration
public IEnumerable<Line> Lines { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Line>
| Improve this Doc View Source

Linetypes

Gets the Linetypes collection.

Declaration
public Linetypes Linetypes { get; }
Property Value
Type Description
Linetypes
| Improve this Doc View Source

LwPolylines

Gets the LwPolyline list in the active layout.

Declaration
public IEnumerable<LwPolyline> LwPolylines { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<LwPolyline>
| Improve this Doc View Source

Meshes

Gets the Mesh list in the active layout.

Declaration
public IEnumerable<Mesh> Meshes { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Mesh>
| Improve this Doc View Source

MLines

Gets the MLine list in the active layout.

Declaration
public IEnumerable<MLine> MLines { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<MLine>
| Improve this Doc View Source

MlineStyles

Gets the MLineStyles collection.

Declaration
public MLineStyles MlineStyles { get; }
Property Value
Type Description
MLineStyles
| Improve this Doc View Source

MTexts

Gets the MText list in the active layout.

Declaration
public IEnumerable<MText> MTexts { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<MText>
| Improve this Doc View Source

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.

| Improve this Doc View Source

Points

Gets the Point list in the active layout.

Declaration
public IEnumerable<Point> Points { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Point>
| Improve this Doc View Source

PolyfaceMeshes

Gets the PolyfaceMeshes list in the active layout.

Declaration
public IEnumerable<PolyfaceMesh> PolyfaceMeshes { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<PolyfaceMesh>
| Improve this Doc View Source

Polylines

Gets the Polyline list in the active layout.

Declaration
public IEnumerable<Polyline> Polylines { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Polyline>
| Improve this Doc View Source

RasterVariables

Gets or sets the RasterVariables applied to image entities.

Declaration
public RasterVariables RasterVariables { get; set; }
Property Value
Type Description
RasterVariables
| Improve this Doc View Source

Rays

Gets the Ray list in the active layout.

Declaration
public IEnumerable<Ray> Rays { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Ray>
| Improve this Doc View Source

Shapes

Gets the Shape list in the active layout.

Declaration
public IEnumerable<Shape> Shapes { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Shape>
| Improve this Doc View Source

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.

| Improve this Doc View Source

Solids

Gets the Solid list in the active layout.

Declaration
public IEnumerable<Solid> Solids { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Solid>
| Improve this Doc View Source

Splines

Gets the Spline list in the active layout.

Declaration
public IEnumerable<Spline> Splines { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Spline>
| Improve this Doc View Source

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.

| Improve this Doc View Source

Texts

Gets the Text list in the active layout.

Declaration
public IEnumerable<Text> Texts { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Text>
| Improve this Doc View Source

TextStyles

Gets the TextStyles collection.

Declaration
public TextStyles TextStyles { get; }
Property Value
Type Description
TextStyles
| Improve this Doc View Source

Tolerances

Gets the Tolerance list in the active layout.

Declaration
public IEnumerable<Tolerance> Tolerances { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Tolerance>
| Improve this Doc View Source

Traces

Gets the Trace list in the active layout.

Declaration
public IEnumerable<Trace> Traces { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Trace>
| Improve this Doc View Source

UCSs

Gets the UCSs collection.

Declaration
public UCSs UCSs { get; }
Property Value
Type Description
UCSs
| Improve this Doc View Source

UnderlayDgnDefinitions

Gets the UnderlayDgnDefinitions collection.

Declaration
public UnderlayDgnDefinitions UnderlayDgnDefinitions { get; }
Property Value
Type Description
UnderlayDgnDefinitions
| Improve this Doc View Source

UnderlayDwfDefinitions

Gets the UnderlayDwfDefinitions collection.

Declaration
public UnderlayDwfDefinitions UnderlayDwfDefinitions { get; }
Property Value
Type Description
UnderlayDwfDefinitions
| Improve this Doc View Source

UnderlayPdfDefinitions

Gets the UnderlayPdfDefinitions collection.

Declaration
public UnderlayPdfDefinitions UnderlayPdfDefinitions { get; }
Property Value
Type Description
UnderlayPdfDefinitions
| Improve this Doc View Source

Underlays

Gets the Underlay list in the active layout.

Declaration
public IEnumerable<Underlay> Underlays { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Underlay>
| Improve this Doc View Source

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.

| Improve this Doc View Source

Viewports

Gets the Viewport list in the active layout.

Declaration
public IEnumerable<Viewport> Viewports { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Viewport>
| Improve this Doc View Source

VPorts

Gets the VPorts collection.

Declaration
public VPorts VPorts { get; }
Property Value
Type Description
VPorts
| Improve this Doc View Source

Wipeouts

Gets the Wipeout list in the active layout.

Declaration
public IEnumerable<Wipeout> Wipeouts { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Wipeout>
| Improve this Doc View Source

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 Source

AddEntity(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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX