GithubHelp home page GithubHelp logo

gdsestimating / dxf-parser Goto Github PK

View Code? Open in Web Editor NEW
433.0 32.0 131.0 1.37 MB

A javascript parser for DXF files. It reads DXF file strings into one large javascript object with more readable properties and a more logical structure.

License: MIT License

JavaScript 9.16% TypeScript 90.84%

dxf-parser's Introduction

Dxf-Parser

Dxf Parser is a javascript parser for dxf files. It reads dxf files into one large javascript object with readable properties and a more logical structure.

Also, keep an eye on three-dxf, a browser module for rendering the output of Dxf-Parser in the browser.

Install

npm install dxf-parser

Browsers -- As of 0.1.3 standalone browserify version is in the commonjs/ folder. Copy it out of the install directory or just download it from the GitHub repo directly. We may evetually publish this to bower, but the build environment needs a little work first.

Usage

import DxfParser from 'dxf-parser';

// Grab fileText in node.js or browser
const fileText = ...;

const parser = new DxfParser();
try {
    const dxf = parser.parse(fileText);
} catch(err) {
    return console.error(err.stack);
}

See the wiki Example Output page to get an idea of what the results look like.

Run Samples

node.js

npm install
npm run build
node samples/node/parseSync
node samples/node/parseStream

browser - the three-dxf repo has a sample for viewing dxf cad in the browser

What's Supported

Support

  • Header
  • Most 2D entities
  • Layers
  • LType table
  • Block table and inserts
  • VPort table
  • Text and some MTEXT
  • Some XData

Does not yet support

  • 3DSolids
  • All types of Leaders
  • other less common objects and entities.

Contributing

See the wiki for info on contributing

Run Tests

npm install -g mocha
//Then
npm test
//OR
mocha test

dxf-parser's People

Contributors

alecmev avatar bzuillsmith avatar camnewnham avatar danmarshall avatar darcyparker avatar gpbmike avatar iceblu3710 avatar jakubnavratil avatar kpetrow avatar mankyd avatar pentacular avatar serthys avatar sigill avatar supporting avatar taoqf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dxf-parser's Issues

Name of Dynamic Block Inserts

Hey there,

I was wondering if there is a way to get the name of a dynamic block from an inserted instance?

Currently I am getting objects with values such as these:

{
    type: 'INSERT',
    handle: '16D8',
    ownerHandle: '2',
    layer: 'Tracing',
    lineweight: 25,
    name: '*U146',  // <------------- Would like an actual name which I can see in AutoCAD but not in the parsed value
    position: { x: 407.6777181310168, y: 883.6808549083853, z: 0 },
    xScale: -1,
    rotation: 89.99999564094279
  }

Thanks in advance!

Need INSERT entity support

Adding INSERTS will be a big easy win because they are required for inserting blocks into a drawing. We are already parsing blocks so it should be easy enough to add this and complete the basics of block support

ReferenceError: checkCommonEntityProperties is not defined

First, thanks for the contributors for this very nice library.

I am using a dxf-parser (last master version) to read a dxf file (3D face I think).
When parsing the file, I am getting an error:

ReferenceError: checkCommonEntityProperties is not defined
    at EntityParser.parseEntity (dxf-parser.js:1296)
    at parseEntities (dxf-parser.js:1070)
    at parseAll (dxf-parser.js:531)
    at DxfParser._parse (dxf-parser.js:1127)
    at DxfParser.parseSync (dxf-parser.js:463)

I am not understanding why I am getting this error.
In case someone could give some hints to understand what I did wrong, that would be nice.

I looked in the opened and closed issues of this github, but I did not find similar post.

Here is the file (in txt format as github won't accept *.dxf)
my3Ddxf.txt

Question - Ability to read group of elements

I was just trying to figure out if I am reading a DXF file that has multiple elements grouped, how to read this group from when parsing the DXF file. Attached is a screen of what I am trying to read, I can read each element individually, but I need to read the group and parse all elements in the group.

Captura de Pantalla 2022-04-02 a la(s) 21 03 54

Big MTEXT Parsing bug

Hello

I spot an bug in the code while trying to read a big MTEXT.

I corrected it by modifying the following code in the mtext.js file

from

case 1:
entity.text = curr.value;
break;
case 3:
entity.text + = curr.value;
break;

to

case 1:
entity.text? entity.text + = curr.value : entity.text = curr.value;
break;
case 3:
entity.text? entity.text += curr.value : entity.text = curr.value;
break;

thanks for your great work
xlionis

The angle always in radians

I have a DXF where the $DIMAUNIT says the angles are in decimal degrees but the output JSON file has all the angles in radians. Well not all, but the ones for ARC and CIRCLE entities while the $DIMAUNIT in the header still says the values are in decimal degrees. Please skip the conversion of dec degrees to radians in the ARC/CIRCLE entities and keep there the original value.

`loglevel` causes compilation warning

I am using webpack to package the app. Why do I include loglevel in the package I am publishing?
This may cause some problems.

WARNING in ../PROJECT/node_modules/loglevel/lib/loglevel.js
There are multiple modules with names that only differ in casing.
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
Use equal casing. Compare these module identifiers:
* D:\Dev\PROJECT\node_modules\loglevel\lib\loglevel.js
    Used by 1 module(s), i. e.
    D:\Dev\PROJECT\node_modules\webpack-dev-server\client\utils\log.js
* D:\Dev\PROJECT\node_modules\loglevel\lib\loglevel.js
    Used by 1 module(s), i. e.
    D:\Dev\PROJECT\node_modules\dxf-parser\src\DxfParser.js
 @ ../PROJECT/node_modules/loglevel/lib/loglevel.js
 @ ../PROJECT/node_modules/webpack-dev-server/client/utils/log.js
 @ ../PROJECT/node_modules/webpack-dev-server/client?http://0.0.0.0:7778
 @ multi ../PROJECT/node_modules/webpack-dev-server/client?http://0.0.0.0:7778 ../PROJECT/node_modules/webpack/hot/dev-server.js ./src/index.tsx
Child html-webpack-plugin for "index.html":
                                   Asset      Size  Chunks             Chunk Names      
    90ff598512a8eb717c8b.hot-update.json  44 bytes          [emitted]
     + 1 hidden asset
    Entrypoint undefined = index.html
       3 modules
i 「wdm」: Compiled with warnings.

Support for pdf

I have a pdf file with multiple dxf images. I have attached sample pdf. Please help me how to extract this pdf using javascript/nodeJs. Please let me know any
Sample Vector PDF_outlines.pdf
suggestions. Thanks

Need tests for entities

We still need automated tests on the following entities since they are not covered in any form by the current tests:

  • 3DFACE
  • DIMENSION
  • ARC
  • MTEXT

Parsing blocks with attributes

Hello :)
I previously used an older version of the library (^ 1.0.0-alpha.2), and recently updated it to the new version (^ 1.1.2).
I have noticed that there is a difference in the way dxf blocks are analyzed and interpreted. The difference is about the features of the block. In the old version you used to add them as a "ATTRIB" feature to the data, and in the new one I did not find this data.
Can you please clarify the issue?
Should the data be stored somewhere?
Did you mean to do that?

Layer Visible Issues

Awesome library. I wrote my own parser not knowing this was out there and month later decided to abandon ship for this great library. The final straw was code 38 elevations for polylines instead of code 30 for vertex elevations.... THANKS!

for reference i use the dxf manual found here

In the following example one layer, is invisible(negative code 62 color), one layer is frozen and should not be visible( value 1 for code 70) and one layer is visible(positive value for code 62 and value zero for code 70)
DXF snippet:

100
AcDbSymbolTableRecord
100
AcDbLayerTableRecord
2
EXISTING
70
0 // not frozen and visible
62
2 //positive and visible
6
DASHED
370
-3
390
F
0
LAYER
5
3C
102
{ACAD_XDICTIONARY
360
42A
102
}
330
2
100
AcDbSymbolTableRecord
100
AcDbLayerTableRecord
2
FINAL
70
0 // not frozen and visible
62
-1 // negative color means layer FINAL off
6
Continuous
370
-3
390
F
0
LAYER
5
3D
102
{ACAD_XDICTIONARY
360
42C
102
}
330
2
100
AcDbSymbolTableRecord
100
AcDbLayerTableRecord
2
PNTDESC
70
1 // layer PNTDESC should be frozen and invisible
62
3
6
Continuous
370
-3
390
F
0
LAYER
5
3F
102
{ACAD_XDICTIONARY
360
430
102
}
330
2

JSON snippet:

"layer": {
"handle": "2",
"ownerHandle": "0",
"layers": {
"EXISTING": {
"name": "EXISTING",
"visible": false, //This is the one visible layer (code 70 = 0 && code 62 is positive
"color": 16776960
},
"FINAL": {
"name": "FINAL",
"visible": true, // this layer has negative color means not visible
"color": 16711680
},
"PNTDESC": {
"name": "PNTDESC",
"visible": false, // this layer is frozen should not be visible
"color": 65280
},

looks like line 533 of DxfParser.js is backwards:
layer.visible = curr.value <= 0;
should be
layer.visible = curr.value > 0;

And you do not check for frozen layers??

possibly add in this code into parseLayers.

case 70: // frozen layer
     layer.frozen = (curr.value != 1 &&  curr.value != 2 );
     curr = scanner.next();
     break;

OR dirtier:

case 62: // color, visibility
     layer.visible = (layer.visible && curr.value > 0);` // code 70 is always prior to 62
     layer.color = getAcadColor(Math.abs(curr.value));
     curr = scanner.next();
     break;

case 70: // frozen layer
     layer.visible = (curr.value != 1 &&  curr.value != 2 );
     curr = scanner.next();
     break;

Types?

Hi!

Silly question but how do I generate/find the types? package.json says it should be in ./esm/index.d.ts but that folder doesn't exist :(

Thanks :-)

Unintentional skipping of Group code

return vertices;

When we are on this lane because we detected group code NOT from VERTEX but from LWPOLYLINE, we should call

scanner.rewind();

before returning.
So when we jump back to looping over LWPOLYLINE group codes, we dont skip one.
Effectively this skips 210 code which is extrusionDirectionX and it is missing from entity.

Easy fix and makes sense :)

OCS extrusion direction for LWPOLYLINE

Looks like extrusion direction was only implemented for ATTDEF. Extrusion can be part of LWPOLYLINE along with a bunch of other entities. The biggest issue with current code is that parseLWPolylineVertices runs through the rest of the entity but code 210, 220, 230 are at the end of the entity and apply to the entity not the vertices. To solve this I ended up passing the entity into the parseVertex function so we can grab the extrusion directions and append them to the entity:

line 1106:
entity.vertices = parseLWPolylineVertices(numberOfVertices, entity);

and then add the code to the parseLWPolylineVertices function:

var parseLWPolylineVertices = function(n, entity) {
		if(!n || n <= 0) throw Error('n must be greater than 0 verticies');
		var vertices = [], i;
		var vertexIsStarted = false;
		var vertexIsFinished = false;

		for(i = 0; i < n; i++) {
			var vertex = {};
			while(curr !== 'EOF') {
				if(curr.code === 0 || vertexIsFinished) break;

				switch(curr.code) {
					case 10: // X
						if(vertexIsStarted) {
							vertexIsFinished = true;
							continue;
						}
						vertex.x = curr.value;
						vertexIsStarted = true;
						break;
					case 20: // Y
						vertex.y = curr.value;
						break;
					case 30: // Z
						vertex.z = curr.value;
						break;
					case 40: // start width
						vertex.startWidth = curr.value;
						break;
					case 41: // end width
						vertex.endWidth = curr.value;
						break;
					case 42: // bulge
						if(curr.value != 0) vertex.bulge = curr.value;
						break;
					case 210: // OCS extruding x
						entity.extrusionDirectionX = curr.value;
						break;
					case 220: // OCS extruding x
						entity.extrusionDirectionY = curr.value;
						break;
					case 230: // OCS extruding x
						entity.extrusionDirectionZ = curr.value;
						break;
					default:
						//todo: mark unhandled somehow?
						curr = scanner.next();
						continue;
				}
				curr = scanner.next();
			}
			// See https://groups.google.com/forum/#!topic/comp.cad.autocad/9gn8s5O_w6E
			vertices.push(vertex);
			vertexIsStarted = false;
			vertexIsFinished = false;
		}
		return vertices;
	};

This probably needs to be implemented for all vertex functions,

I guess now that we pass in the entity we could directly add the vertices, but this is least amount of changes. Now the fun of converting Object coordinates to world..... Anybody got that code?

The problem of analytic coding

DXF encodes ANSI by default, and DXF parser resolves to UTF-8. Please help to solve this problem, convert ANSI code to UTF-8 when reading

Wrong AutoCadColorIndex

I think some colors on dxf-parser/lib/AutoCadColorIndex.js are wrong or maybe the definition changed.
I've checked some of them, for example, the AutoCadColorIndex[154] = 19608 = 0x004C98 = (0, 76, 152) and on my AutoCAD 2014 the indexed color 154 is (0, 63, 127).
I investigated a bit to find the correct colors and I found some ACI (AutoCAD Color Index) tables but those don't match either.
ACI table 1[154] = (0, 64, 129)
ACI table 2[154] = (0, 76, 153)
I'm not sure how to fix this.

Group code does not have a defined type:

Screenshot 2023-02-02 at 13 04 49

I have a valid dxf file. I successfully opened it in another file viewer. But When I tried to parse it I got the error **Group code does not have a defined type:** {code: NaN, value: '310'} dxf-parser version: 1.1.2

Support for multiple custom properties

A DXF file can contain multiple custom properties. Currently the parser thinks there's only one custom property and outputs "$CUSTOMPROPERTYTAG": "<Property Name>" and "$CUSTOMPROPERTY": "<Property Value>". The selected custom property happens to be the last one since the others are overridden by the last one. This structure should be something like:

"CUSTOMPROPERTIES": {
  "<Property Name>": "<Property Value>",
  "<Property Name>": "<Property Value>"
}

If this messes up the naming convention, $CUSTOMPROPERTIES can be used.

How can get perimeter of DXF File ?

hi, i used this codes in WordPress, of course DXFviewer plugin, now i need know how can get data from dxf file for example how can get perimeter of model that included in dxf file.
thanks

npm or yarn?

I see both package-lock.json and yarn.lock files in the repo.

Running npm install modifies both package.json and package-lock.json.

Running yarn install modifies yarn.lock.

The contributing wiki does not indicate a preference.

Seems like one of the lock files should be removed and the other should be updated and committed.

I'm not the most proficient npm/yarn user so I apologize if I am missing something obvious here.

package-lock.json changes after npm install

image

yarn.lock changes after yarn install (truncated)

image

Compilation issue with ParseHelpers

Hi, iam updating packages in my project and after dxf-parser update i got compilation error:

Error: node_modules/dxf-parser/src/ParseHelpers.ts:112:4 - error TS2322: Type '{ customStrings: string[]; applicationName: string; } | {}' is not assignable to type '{ customStrings: string[]; applicationName: string; }'.
Type '{}' is missing the following properties from type '{ customStrings: string[]; applicationName: string; }': customStrings, applicationName

112 entity.extendedData = entity.extendedData || {};

image

as you can see IEntity.extendedData has 2 required params but you are assigning {} in some case.

Can you fix it ASAP, i want to update this package because it is now in TS with types but i cannot do it with compilation error.

Btw best solution should be to use somethink like DxfEntityAny instead of IEntity.

export type DxfEntityAny = I3DfaceEntity|IArcEntity|IAttdefEntity|ICircleEntity|IDimensionEntity|IEllipseEntity|IInsertEntity|ILineEntity| ILwpolylineEntity|IMtextEntity|IPointEntity|IPolylineEntity|ISolidEntity|ISplineEntity|ITextEntity| IVertexEntity;

Entities with type SOLID are not handled properly

I tried parsing files with entities of the types LINE, POLYLINE and POINT, and they all came out as they should.

I also had a test with a polygon which should have the type SOLID (it might also be HATCH by looking at the source, I just know this is the type of data I need to read). However, this time the "entities" array is empty.

I've attached the .dxf-file here (but renamed it with a txt-extension for github upload):
areas_test.txt

Property HATCH

Would it be possible to read the hatch property within an entity?

Publish a new version?

Hello,

Would it be possible to publish a new npm?

The require / import fix needs manual patching until this happens :(

Thanks.

Normalize() group transforms

First of all, thank you for an amazing work!

I'm just curious, is it possible to add normalize() function into the library, to unwind... to apply all block transforms to the endpoints and shapes?

Thanks again

Bringing up to a newer standard than R12

Are there currently any plans to bring the parser up to current file standards. Currently all R12 entities are supported it looks like but some program seem to be dropping R12 export/save capabilities.

Vertex returns incorrect bulge value in some cases

A vertex with a start and end width defined, but a bulge value of 0 returns a non-zero bulge.

I think there is a missing "break" statement after case 40 and case 41 in the vertex parser. Case 41 is hit for the end width, which falls through to case 42. Since the end width is nonzero (curr.value != 0) evaluates to true and the bulge is set to the end width. When the bulge is parsed, and case 42 is hit again, the bulge is actually 0, which then fails to zero or remove the bulge property.

Adding a "break" to case 41 fixes the issue.

If you need, I can try and figure out how to submit a pull request!

BLOCK parsing does not stop when ENDBLK is encountered

I have a dxf file with the following BLOCKS section, and it seems to confuse/break parsing. Stepping through the code, it looks like, after encountering an ENDBLK, it continues parsing the block, until it finally encounters a AcDbBlockEnd, which does not occur in my file.

BLOCKS
0
BLOCK
8
0
2
$MODEL_SPACE
70
0
10
0.0
20
0.0
30
0.0
3
$MODEL_SPACE
1

0
ENDBLK
5
21
8
0
0
BLOCK
67
1
8
0
2
$PAPER_SPACE
70
0
10
0.0
20
0.0
30
0.0
3
$PAPER_SPACE
1

0
ENDBLK
5
1D
67
1
8
0
0
ENDSEC

How to handle large points

Hello,

I have a dxf file and i am using your parser to read it and getting huge points like this

vertices: Array(5)
new THREE.Vector3(11480992.59240649,3454785.183761712,0)
new THREE.Vector3(11481107.78168301,3454732.692403951,0)
new THREE.Vector3(11481100.31350271,3454716.314788647,0)
new THREE.Vector3(11480985.23491298,3454768.755673313,0)
new THREE.Vector3(11480992.59240649,3454785.183761712,0)

Now in three js the scene you know is really small and i want to make this polylines visible, so how i can scale or transform them, whats your unit system here in the conversion if the file unit is feet or meter

DxfParser export seems broken

DxfParser is exported as undefined

I've been able to work around this by

import dxfParserModule from 'dxf-parser';
const DxfParser = dxfParserModule.default;

but this should probably be fixed more nicely sometime.

`TypeError: Cannot call a class as a function` in tests

After pulling down the repo, building, and running tests, I get the following errors.

  Scanner
    .hasNext()
      ✓ should return false when the array is empty
      ✓ should return false when the array has length 1
      ✓ should return true when the array has length 2
      ✓ should return false when the array has length 4 and pointer is on the last element
      ✓ should return true when the array has length 4 and pointer is on the second-to-last element
    .next()
      ✓ should throw an error when the array is empty
      ✓ should throw an error when the array has only 1 element
      ✓ should throw an error when next is called and eof has already been read
      ✓ should return the 1st and 2nd index as the code and value respectively
      ✓ should set _eof to true when EOF code-value pair is read
      ✓ should increment the pointer by 2
    .isEOF()
      ✓ should be true when _eof is true

  Parser
    ✓ should parse the dxf header variables into an object
    ✓ should parse the tables section without error
    ✓ should parse the dxf layers
    ✓ should parse the dxf ltype table
    ✓ should parse the dxf viewPort table
    1) should parse a complex BLOCKS section
    ✓ should parse a simple BLOCKS section
    2) should parse POLYLINES
    ✓ should parse ELLIPSE entities
    ✓ should parse SPLINE entities
    ✓ should parse EXTENDED DATA
    3) should parse SPLINE entities that are like arcs and circles
    4) should parse ARC entities (1)
    5) should parse MTEXT entities


  21 passing (97ms)
  5 failing

  1) Parser
       should parse a complex BLOCKS section:
     TypeError: Cannot call a class as a function
      at _classCallCheck (dist/DxfParser.js:48:99)
      at DxfParser (dist/DxfParser.js:46:19)
      at verifyDxf (test/DxfParser.test.js:184:12)
      at Context.<anonymous> (test/DxfParser.test.js:88:3)
      at processImmediate (internal/timers.js:464:21)

  2) Parser
       should parse POLYLINES:
     TypeError: Cannot call a class as a function
      at _classCallCheck (dist/DxfParser.js:48:99)
      at DxfParser (dist/DxfParser.js:46:19)
      at verifyDxf (test/DxfParser.test.js:184:12)
      at Context.<anonymous> (test/DxfParser.test.js:110:3)
      at processImmediate (internal/timers.js:464:21)

  3) Parser
       should parse SPLINE entities that are like arcs and circles:
     TypeError: Cannot call a class as a function
      at _classCallCheck (dist/DxfParser.js:48:99)
      at DxfParser (dist/DxfParser.js:46:19)
      at verifyDxf (test/DxfParser.test.js:184:12)
      at Context.<anonymous> (test/DxfParser.test.js:166:3)
      at processImmediate (internal/timers.js:464:21)

  4) Parser
       should parse ARC entities (1):
     TypeError: Cannot call a class as a function
      at _classCallCheck (dist/DxfParser.js:48:99)
      at DxfParser (dist/DxfParser.js:46:19)
      at verifyDxf (test/DxfParser.test.js:184:12)
      at Context.<anonymous> (test/DxfParser.test.js:170:3)
      at processImmediate (internal/timers.js:464:21)

  5) Parser
       should parse MTEXT entities:
     TypeError: Cannot call a class as a function
      at _classCallCheck (dist/DxfParser.js:48:99)
      at DxfParser (dist/DxfParser.js:46:19)
      at verifyDxf (test/DxfParser.test.js:184:12)
      at Context.<anonymous> (test/DxfParser.test.js:174:3)
      at processImmediate (internal/timers.js:464:21)



npm ERR! Test failed.  See above for more details.

Seems related to #78.

I think the following change needs to be reverted: 8762566#diff-9bb7bb43870d7fb6b2a037138c18ce7df3c9030dc207e6c16e9ea2ab16f364fd

Uncaught TypeError: window.DxfParser is not a constructor

I get an error when trying to call var parser = new window.DxfParser

The error is

TypeError: window.DxfParser is not a constructor
    at window.onload

dxf-parser.js is included in the head of the html file and I can see dxf-parser.js is loaded in the sources.

Parse Splines

Hey there,

Is possible parse Splines with this library?, If not, any way for this purpose?

Thanks in advance.

Exception when parsing

I integrated the parser in a node.js app and I get this error on a fairly complex cad:

Error: Expected code for point value to be 50 but got 41.
at parsePoint (.\dev\dxf-parser\tools\dxf-parser.js:1217:11)
at parsePolylinePoints (.\dev\dxf-parser\tools\dxf-parser.js:1236:13)
at parseLWPOLYLINE (.\dev\dxf-parser\tools\dxf-parser.js:1443:24)
at parseEntities (.\dev\dxf-parser\tools\dxf-parser.js:987:15)
at parseBlock (.\dev\dxf-parser\tools\dxf-parser.js:621:23)
at parseBlocks (.\dev\dxf-parser\tools\dxf-parser.js:552:13)
at parseAll (.\dev\dxf-parser\tools\dxf-parser.js:470:19)
at DxfParser._parse (.\dev\dxf-parser\tools\dxf-parser.js:1735:2)
at ReadStream.onEnd (.\dev\dxf-parser\tools\dxf-parser.js:432:19)
...

DXF parser to DXF file

Hello,

For one project I need to extract some layers of one DXF file to generate another DXF file.

I thank use dxf-parser to generate the list of my layers but how transform the JSON object in new DXF file..

Do you have any idea how I can do this ?

Regards,
Damien

Handling illegal values in group codes

I have noticed a few times now that programs are outputting illegal values with group codes. A simple example is

POLYLINE
  5
497
  8
0
 66
     1
 10
0.0
 20
0.0
 30
0.0
 70
   129
  0
VERTEX
  5
57E
  8
0
 10
210.0
 20
195.0
 30
0.0
  0
VERTEX
  5
57F
  8
0
 10
10.0
 20
195.0
 30
0.0
  0
VERTEX
  5
580
  8
0
 10
10.0
 20
145.0
 30
0.0
  0
VERTEX
  5
581
  8
0
 10
210.0
 20
145.0
 30
0.0
  0
SEQEND
  5
674
  8
0
  0

So this closed shape is listed as false because 70: 129 is illegal, default to 70: 0. The program that output simpily did a +1 to close the shape.

DraftSight reads in the file properly however so there must be some error handling. Possibly an if val > 128 then val -=128 ??

output to SVG?

Has anyone used this to convert to SVG? Or is there already an open-source API for converting DXF (ideally DWG) to SVG?

Support for 3dFace entity

I have added two functions for 3d face support that mimic the polyline parser but only parse 4 vertices (max for a 3dFace, seems weird to have a non triangle face??) Will file PR tomorrow when the code is cleaned up.

Parse via streaming for huge files

I'm trying to parse a 1.1GB file in an electron app. However, an Invalid String Length exception is being raised on this line:

function onData(chunk) {
	dxfString += chunk;
}

https://github.com/gdsestimating/dxf-parser/blob/master/src/DxfParser.js#L84

I believe that dxfString string is being built up to exceed to the 1GB limit on strings in V8.

It seems that this could be fixed by streaming the file contents into the parser rather than crawling through a giant string.

I'm not familiar enough with the DXF format to know if it's parseable without having all of it loaded, but I think it may be?

If handles are missing, the file is not parsed correctly

A lack of handles causes the tables to only have a single element with a key of 'undefined'. We should autoincrement a counter in this case. According to most sources for the DXF reference, handles are required and are simply a unique id for all objects/entities in hex format.

String Base 64

Is there a way to parse a file that was get via event.target.files[0], type string (Base 64) ? When I try to parse let dxf = parser.parseSync(this.state.data); I receive an error: Empty File in the function _parse (node_modules/dxf-parser/lib/DxfParser.js).

Example of string:

image

How to extract mesh geometry from polylines?

How should I create faces and vertices from 3D points list? (dxf.entities -> type = 'POLYLINE')

I have tried this:

function addTriangle(g, p, i1, i2, i3) {
    if(Math.max(i1, i2, i3) > p.length - 1) return; 
    let p1 = p[i1];
    let p2 = p[i2];
    let p3 = p[i3];
    g.vertices.push(new THREE.Vector3( p1.x, p1.y, p1.z ))
    g.vertices.push(new THREE.Vector3( p2.x, p2.y, p2.z ))
    g.vertices.push(new THREE.Vector3( p3.x, p3.y, p3.z ))
    g.faces.push(new THREE.Face3(g.vertices.length - 3, g.vertices.length - 2, g.vertices.length - 1))
}

    var g = new THREE.Geometry();


    polylines.map(p => {
        for(let i=0;i<p.length;i+=6) {
            addTriangle(g, p, i, i+1, i+2)
            addTriangle(g, p, i+3, i+1, i)
        }
    })

But several polygons are missed. Moreover, I see a few points with a zero coordinates
Kazam_screenshot_00003

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.