benjist
benjist

Reputation: 2881

DXF/DWG internals: Is a block's name unique?

I'm writing a DXF/DWG object dumper. The dumper exports all data hierarchically, and later converts this full data set into GeoJson or CSV-WKT alternatively.

One thing I stumble on is that my internal hierarchy stores all dumped blocks on the same hierarchy level as a dictionary:

entities->block1->...data...
entities->block2->...data...

I did not yet se any issue, though since I store this as a map and thus block names need to be unique keys, I wonder whether or not this assumption is true.

So, are block names unique? And do blocks always have a name? Can there be non-user created blocks which do not have a unique name, even though user-created blocks are indeed unique?

Upvotes: 0

Views: 1150

Answers (2)

abenci
abenci

Reputation: 8651

AutoCAD blocks are symbols that can be inserted in the drawing many times in different locations with different angle and scale (even not uniform scaling). Each block's entity list can contain a block reference generating a nested structure. Your implementation needs therefore recursive methods that deal with multilevel object nesting.

Yes, block's name are unique and can be stored as a dictionary key.

Upvotes: 0

Andrew Truckle
Andrew Truckle

Reputation: 19117

If you look here you will get all the info you need about DXF files.

You need to look up on the BLOCKS and ENTITIES INSERT parts.

Blocks have a unique reference with their definition. Then in the drawing are INSERT objects which are instances of the blocks.

It also mentions there:

The BLOCKS section of the DXF file contains all the block definitions. It contains the entities that make up the blocks used in the drawing, including anonymous blocks generated by the HATCH command and by associative dimensioning. The format of the entities in this section is identical to those in the ENTITIES section. All entities in the BLOCKS section appear between block and endblk entities. Block and endblk entities appear only in the BLOCKS section. Block definitions are never nested (that is, no block or endblk entity ever appears within another block-endblk pair), although a block definition can contain an insert entity.

External references are written in the DXF file as block definitions, except that they also include a string (group code 1) that specifies the path and file name of the external reference.

The block table handle, along with any xdata and persistent reactors, appears in each block definition immediately following the BLOCK record, which contains all of the specific information that a block table record stores.

Upvotes: 2

Related Questions