skymakerolof / dxf

DXF parser for node/browser
https://www.npmjs.com/package/dxf
MIT License
335 stars 122 forks source link

Extracting entities attributes #61

Open pranavramkrishnan opened 4 years ago

pranavramkrishnan commented 4 years ago

Hi!

I've found this package extremely useful in trying to run some experiments with AutoCAD/DXF files.

I wanted to understand if there is a way to get entity attributes through this parser? Specifically, attributes for an inserted block entity.

Thanks in advance!

bjnortier commented 4 years ago

If you look in examples/example.es6.js you can see how to access the raw parsed entities (including blocks)

pranavramkrishnan commented 4 years ago

Thanks for the response @bjnortier!

I'm looking to get entity attributes as well as details such as a entity handles.

Based on the example you suggest, here is the code I'm using to parse:

const dxf = new Helper(fs.readFileSync('...', 'utf-8'))

const {blocks, entities} = dxf.parsed

However the entities returned seem to be as such:

{
    type: 'INSERT',
    layer: 'M-CORNER',
    block: '*U57',
    x: 3.431680568112945,
    y: -5.903964967049045,
    z: 0
  }

In AutoCAD - this particular insert as associated attributes (ATTRIB). And I'm also looking to get handles for each entity.

Is there a different way/method I should be using?

Thanks again!

bjnortier commented 4 years ago

Ah I misundersood.

This library doesn't do any parsing of ATTRIB entities unfortunately.

z3dev commented 4 years ago

I’ve been reading this issue, and still don’t understand what’s required.

DXF is a series of blocks, entities, etc. It doesn’t provide any linkage between pieces, except for references, which are typically just strings.

So, no matter what, whatever you want to do, you still have to put the pieces together. For example, the third entity references block 2.