diff --git a/packages/maker.js/src/core/dxf.ts b/packages/maker.js/src/core/dxf.ts index 6ac9e707..3ec08b72 100644 --- a/packages/maker.js/src/core/dxf.ts +++ b/packages/maker.js/src/core/dxf.ts @@ -165,10 +165,11 @@ namespace MakerJs.exporter { return textEntity; } - function layerOut(layerId: string, layerColor: number) { + function layerOut(layerId: string, layerColor: number, layerLineWeight: number) { const layerEntity: DxfParser.Layer = { name: layerId, - color: layerColor + color: layerColor, + lineWeight: layerLineWeight }; return layerEntity; } @@ -195,7 +196,7 @@ namespace MakerJs.exporter { layerIds.forEach(layerId => { var layerOptions = colorLayerOptions(layerId); if (layerOptions) { - layerTable.layers[layerId] = layerOut(layerId, layerOptions.color); + layerTable.layers[layerId] = layerOut(layerId, layerOptions.color, layerOptions.lineWeight); } }); const tableName: DxfParser.TableNames = 'layer'; @@ -207,6 +208,7 @@ namespace MakerJs.exporter { var units = dxfUnit[opts.units]; doc.header["$INSUNITS"] = units; } + doc.header["$LWDISPLAY"] = 1; } function entities(walkedPaths: IWalkPath[], chains: IChainOnLayer[], captions: (ICaption & { layer?: string })[]) { @@ -285,6 +287,7 @@ namespace MakerJs.exporter { map["LINE"] = function (line: DxfParser.EntityLINE) { append("0", "LINE", + "370", "-1", // Set line weight to -1 to use the layer's line weight "8", line.layer, "10", @@ -300,6 +303,7 @@ namespace MakerJs.exporter { map["CIRCLE"] = function (circle: DxfParser.EntityCIRCLE) { append("0", "CIRCLE", + "370", "-1", // Set line weight to -1 to use the layer's line weight "8", circle.layer, "10", @@ -313,6 +317,7 @@ namespace MakerJs.exporter { map["ARC"] = function (arc: DxfParser.EntityARC) { append("0", "ARC", + "370", "-1", // Set line weight to -1 to use the layer's line weight "8", arc.layer, "10", @@ -348,6 +353,7 @@ namespace MakerJs.exporter { map["POLYLINE"] = function (polyline: DxfParser.EntityPOLYLINE) { append("0", "POLYLINE", + "370", "-1", // Set line weight to -1 to use the layer's line weight "8", polyline.layer, "66", @@ -418,6 +424,9 @@ namespace MakerJs.exporter { "6", "CONTINUOUS" ); + if (layer.lineWeight) { + append("370", layer.lineWeight); + } } function lineTypeOut(lineType: DxfParser.LineType) { @@ -523,6 +532,11 @@ namespace MakerJs.exporter { * Text size for TEXT entities. */ fontSize?: number; + + /** + * Line weight to control the thickness of the lines drawn. + */ + lineWeight?: number; } /** @@ -554,3 +568,9 @@ namespace MakerJs.exporter { layer: string; } } + +declare namespace DxfParser { + export interface Layer { + lineWeight?: number; + } +} diff --git a/packages/maker.js/test/dxf.js b/packages/maker.js/test/dxf.js index 52fc6e26..16f4647f 100644 --- a/packages/maker.js/test/dxf.js +++ b/packages/maker.js/test/dxf.js @@ -20,7 +20,7 @@ describe('Export DXF', function() { .addTo(model, 'square'); const expected = [ - '0', 'SECTION', '2', 'HEADER', '9', '$INSUNITS', '70', '1', '0', 'ENDSEC', + '0', 'SECTION', '2', 'HEADER', '9', '$INSUNITS', '70', '1', '9', '$LWDISPLAY', '70', '1', '0', 'ENDSEC', '0', 'SECTION', '2', 'TABLES', '0', 'TABLE', '2', 'LTYPE', '0', 'LTYPE', '72', '65', '70', '64', '2', 'CONTINUOUS', '3', '______', '73', '0', '40', '0', '0', 'ENDTAB', @@ -28,10 +28,10 @@ describe('Export DXF', function() { '0', 'ENDSEC', '0', 'SECTION', '2', 'ENTITIES', - '0', 'LINE', '8', 'square', '10', '0', '20', '0', '11', '50', '21', '0', - '0', 'LINE', '8', 'square', '10', '50', '20', '0', '11', '50', '21', '50', - '0', 'LINE', '8', 'square', '10', '50', '20', '50', '11', '0', '21', '50', - '0', 'LINE', '8', 'square', '10', '0', '20', '50', '11', '0', '21', '0', + '0', 'LINE', '370', '-1', '8', 'square', '10', '0', '20', '0', '11', '50', '21', '0', + '0', 'LINE', '370', '-1', '8', 'square', '10', '50', '20', '0', '11', '50', '21', '50', + '0', 'LINE', '370', '-1', '8', 'square', '10', '50', '20', '50', '11', '0', '21', '50', + '0', 'LINE', '370', '-1', '8', 'square', '10', '0', '20', '50', '11', '0', '21', '0', '0', 'TEXT', '10', '25', '20', '25', '11', '25', '21', '25', '40', '4', '1', 'fold here', '50', '45', '8', 'square', '72', '4', '73', '0', '0', 'ENDSEC', '0', 'EOF'