Class Block
Represents a block definition.
Implements
Inherited Members
Namespace: netDxf.Blocks
Assembly: CADability.dll
Syntax
public class Block : TableObject, IHasXData, ICloneable, IComparable, IComparable<TableObject>, IEquatable<TableObject>
Remarks
Avoid to add any kind of dimensions to the block's entities list, programs loading DXF files with them seems to behave in a weird fashion. This is not applicable when working in the Model and Paper space blocks.
Constructors
| Improve this Doc View SourceBlock(String)
Initializes a new instance of the Block class.
Declaration
public Block(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | Block name. |
Block(String, IEnumerable<EntityObject>)
Initializes a new instance of the Block class.
Declaration
public Block(string name, IEnumerable<EntityObject> entities)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | Block name. |
| System.Collections.Generic.IEnumerable<EntityObject> | entities | The list of entities that make the block. |
Block(String, IEnumerable<EntityObject>, IEnumerable<AttributeDefinition>)
Initializes a new instance of the Block class.
Declaration
public Block(string name, IEnumerable<EntityObject> entities, IEnumerable<AttributeDefinition> attributes)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | Block name. |
| System.Collections.Generic.IEnumerable<EntityObject> | entities | The list of entities that make the block. |
| System.Collections.Generic.IEnumerable<AttributeDefinition> | attributes | The list of attribute definitions that make the block. |
Block(String, String)
Initializes a new instance of the Block class as an external reference drawing.
Declaration
public Block(string name, string xrefFile)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | Block name. |
| System.String | xrefFile | External reference path name. |
Remarks
Only DWG files can be used as externally referenced blocks.
Block(String, String, Boolean)
Initializes a new instance of the Block class as an external reference drawing.
Declaration
public Block(string name, string xrefFile, bool overlay)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | Block name. |
| System.String | xrefFile | External reference path name. |
| System.Boolean | overlay | Specifies if the external reference is an overlay, by default it is set to false. |
Remarks
Only DWG files can be used as externally referenced blocks.
Fields
| Improve this Doc View SourceDefaultModelSpaceName
Default ModelSpace block name.
Declaration
public const string DefaultModelSpaceName = "*Model_Space"
Field Value
| Type | Description |
|---|---|
| System.String |
DefaultPaperSpaceName
Default PaperSpace block name.
Declaration
public const string DefaultPaperSpaceName = "*Paper_Space"
Field Value
| Type | Description |
|---|---|
| System.String |
Properties
| Improve this Doc View SourceAttributeDefinitions
Gets the AttributeDefinition list of the block.
Declaration
public AttributeDefinitionDictionary AttributeDefinitions { get; }
Property Value
| Type | Description |
|---|---|
| AttributeDefinitionDictionary |
Remarks
Null or attribute definitions already owned by another block or document cannot be added to the list. Additionally Paper Space blocks do not contain attribute definitions.
Description
Gets or sets the block description.
Declaration
public string Description { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
Remarks
AutoCAD has an unknown limit on the number of characters for the description when loading an external DXF,
while, on the other hand is perfectly capable of saving a Block description that surpasses such limit.
Keep in mind that when saving a DXF prior to the AutoCad2007 version, non-ASCII characters will be encoded,
therefore a single letter might consume more characters when saved into the DXF.
New line characters are not allowed.
Entities
Gets the EntityObject list of the block.
Declaration
public EntityCollection Entities { get; }
Property Value
| Type | Description |
|---|---|
| EntityCollection |
Remarks
Null entities, attribute definitions or entities already owned by another block or document cannot be added to the list.
Flags
Gets the block-type flags (bit-coded values, may be combined).
Declaration
public BlockTypeFlags Flags { get; }
Property Value
| Type | Description |
|---|---|
| BlockTypeFlags |
IsForInternalUseOnly
All blocks that starts with "*" are for internal use only.
Declaration
public bool IsForInternalUseOnly { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsXRef
Gets if the block is an external reference.
Declaration
public bool IsXRef { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Layer
Gets or sets the block Layer.
Declaration
public Layer Layer { get; set; }
Property Value
| Type | Description |
|---|---|
| Layer |
Remarks
It seems that the block layer is always the default "0" regardless of what is defined here, so it is pointless to change this value.
ModelSpace
Gets the default *Model_Space block.
Declaration
public static Block ModelSpace { get; }
Property Value
| Type | Description |
|---|---|
| Block |
Name
Gets the name of the table object.
Declaration
public string Name { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
Remarks
Table object names are case insensitive.
Origin
Gets or sets the block origin in world coordinates, it is recommended to always keep this value to the default Vector3.Zero.
Declaration
public Vector3 Origin { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector3 |
PaperSpace
Gets the default *Paper_Space block.
Declaration
public static Block PaperSpace { get; }
Property Value
| Type | Description |
|---|---|
| Block |
Record
Gets the block record associated with this block.
Declaration
public BlockRecord Record { get; }
Property Value
| Type | Description |
|---|---|
| BlockRecord |
Remarks
It returns the same object as the owner property.
XrefFile
Gets the external reference path name.
Declaration
public string XrefFile { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Remarks
This property is only applicable to externally referenced blocks.
Methods
| Improve this Doc View SourceClone()
Creates a new Block that is a copy of the current instance.
Declaration
public override object Clone()
Returns
| Type | Description |
|---|---|
| System.Object | A new Block that is a copy of this instance. |
Overrides
| Improve this Doc View SourceClone(String)
Creates a new Block that is a copy of the current instance.
Declaration
public override TableObject Clone(string newName)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | newName | Block name of the copy. |
Returns
| Type | Description |
|---|---|
| TableObject | A new Block that is a copy of this instance. |
Overrides
| Improve this Doc View SourceCreate(DxfDocument, String)
Creates a block from the content of a DxfDocument.
Declaration
public static Block Create(DxfDocument doc, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| DxfDocument | doc | A DxfDocument instance. |
| System.String | name | Name of the new block. |
Returns
| Type | Description |
|---|---|
| Block | The block build from the DxfDocument content. |
Remarks
Only the entities contained in ModelSpace will make part of the block.
Load(String)
Creates a block from an external DXF file.
Declaration
public static Block Load(string file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | DXF file name. |
Returns
| Type | Description |
|---|---|
| Block | The block build from the DXF file content. It will return null if the file has not been able to load. |
Remarks
The name of the block will be the file name without extension, and only the entities contained in ModelSpace will make part of the block.
Load(String, IEnumerable<String>)
Creates a block from an external DXF file.
Declaration
public static Block Load(string file, IEnumerable<string> supportFolders)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | DXF file name. |
| System.Collections.Generic.IEnumerable<System.String> | supportFolders | List of the document support folders. |
Returns
| Type | Description |
|---|---|
| Block | The block build from the DXF file content. It will return null if the file has not been able to load. |
Remarks
The name of the block will be the file name without extension, and only the entities contained in ModelSpace will make part of the block.
Load(String, String)
Creates a block from an external DXF file.
Declaration
public static Block Load(string file, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | DXF file name. |
| System.String | name | Name of the new block. |
Returns
| Type | Description |
|---|---|
| Block | The block build from the DXF file content. It will return null if the file has not been able to load. |
Remarks
Only the entities contained in ModelSpace will make part of the block.
Load(String, String, IEnumerable<String>)
Creates a block from an external DXF file.
Declaration
public static Block Load(string file, string name, IEnumerable<string> supportFolders)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | DXF file name. |
| System.String | name | Name of the new block. |
| System.Collections.Generic.IEnumerable<System.String> | supportFolders | List of the document support folders. |
Returns
| Type | Description |
|---|---|
| Block | The block build from the DXF file content. It will return null if the file has not been able to load. |
Remarks
Only the entities contained in ModelSpace will make part of the block.
OnAttributeDefinitionAddedEvent(AttributeDefinition)
Declaration
protected virtual void OnAttributeDefinitionAddedEvent(AttributeDefinition item)
Parameters
| Type | Name | Description |
|---|---|---|
| AttributeDefinition | item |
OnAttributeDefinitionRemovedEvent(AttributeDefinition)
Declaration
protected virtual void OnAttributeDefinitionRemovedEvent(AttributeDefinition item)
Parameters
| Type | Name | Description |
|---|---|---|
| AttributeDefinition | item |
OnEntityAddedEvent(EntityObject)
Declaration
protected virtual void OnEntityAddedEvent(EntityObject item)
Parameters
| Type | Name | Description |
|---|---|---|
| EntityObject | item |
OnEntityRemovedEvent(EntityObject)
Declaration
protected virtual void OnEntityRemovedEvent(EntityObject item)
Parameters
| Type | Name | Description |
|---|---|---|
| EntityObject | item |
OnLayerChangedEvent(Layer, Layer)
Declaration
protected virtual Layer OnLayerChangedEvent(Layer oldLayer, Layer newLayer)
Parameters
| Type | Name | Description |
|---|---|---|
| Layer | oldLayer | |
| Layer | newLayer |
Returns
| Type | Description |
|---|---|
| Layer |
Save(String, DxfVersion)
Saves a block to a text DXF file.
Declaration
public bool Save(string file, DxfVersion version)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | DXF file name. |
| DxfVersion | version | Version of the DXF database version. |
Returns
| Type | Description |
|---|---|
| System.Boolean | Return true if the file has been successfully save, false otherwise. |
Save(String, DxfVersion, Boolean)
Saves a block to a DXF file.
Declaration
public bool Save(string file, DxfVersion version, bool isBinary)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | DXF file name. |
| DxfVersion | version | Version of the DXF database version. |
| 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. |
Events
| Improve this Doc View SourceAttributeDefinitionAdded
Declaration
public event Block.AttributeDefinitionAddedEventHandler AttributeDefinitionAdded
Event Type
| Type | Description |
|---|---|
| Block.AttributeDefinitionAddedEventHandler |
AttributeDefinitionRemoved
Declaration
public event Block.AttributeDefinitionRemovedEventHandler AttributeDefinitionRemoved
Event Type
| Type | Description |
|---|---|
| Block.AttributeDefinitionRemovedEventHandler |
EntityAdded
Declaration
public event Block.EntityAddedEventHandler EntityAdded
Event Type
| Type | Description |
|---|---|
| Block.EntityAddedEventHandler |
EntityRemoved
Declaration
public event Block.EntityRemovedEventHandler EntityRemoved
Event Type
| Type | Description |
|---|---|
| Block.EntityRemovedEventHandler |
LayerChanged
Declaration
public event Block.LayerChangedEventHandler LayerChanged
Event Type
| Type | Description |
|---|---|
| Block.LayerChangedEventHandler |