Skip to main content
OCCT category icon with a stylized logo representation

Writing and Reading 2D Drawings with DXF

The DXF file format has been a cornerstone of CAD workflows for decades, serving as a universal language that allows different design applications to exchange 2D drawing data. Whether you're working with AutoCAD, LibreCAD, or any other major CAD software, chances are it speaks DXF. With Bitbybit's new DXF export capabilities powered by our new generator for OCCT, you can now create these industry-standard files directly from your parametric designs, opening up seamless integration with the broader CAD ecosystem.

In this tutorial, we'll explore how to create a complete DXF file that demonstrates the key features of the format. We'll generate stylized text with smooth rounded corners, add decorative hexagonal patterns, and organize everything into properly colored layers. By the end, you'll understand how to transform your 3D shapes into clean 2D drawings that can be used for laser cutting, CNC machining, architectural drawings, or any other application that requires precise 2D geometry.

Understanding the DXF Workflow​

Creating a DXF file from parametric geometry follows a logical sequence that mirrors how you might work in traditional CAD software. First, you design your shapes using Bitbybit's powerful modeling tools. Then you extract the relevant wire geometry that represents the edges and curves you want to export. After that, you convert these wires into DXF paths, which are the fundamental building blocks of the DXF format. Finally, you organize these paths into named layers with specific colors and combine them into a complete DXF file.

The beauty of this workflow is that it gives you complete control over how your geometry is represented in the final output. Lines, arcs, circles, ellipses and splines keep their exact shapes, so a laser cutter or a CNC machine follows the curve you designed rather than an approximation of it, and the same layered paths can be written as SVG too.

DXF is an extensive format with numerous entity types accumulated over decades of development, and Bitbybit works with the geometry at its heart: lines, arcs, circles, ellipses, polylines with their bulges and splines, organised in layers with colours and line types. That covers the drawings that matter for making things, from laser cutting paths to architectural floor plans. Text, dimensions and hatches are not written or read; a file that holds them reads without them, and says so.

The Example: Text and Patterns​

DXF export with layers
Bitbybit Platform

DXF export with layers in Rete

rete logoRete
Script Source (rete)
{
"id": "rete-v2-json",
"nodes": {
"textWithUrl": {
"id": "textWithUrl",
"name": "bitbybit.advanced.text3d.createWithUrl",
"customName": "text with url",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"text": "DXF @ bitbybit.dev",
"fontUrl": "https://git-cdn.bitbybit.dev/latest/fonts/Tektur/Tektur-Bold.ttf",
"fontSize": 1.5,
"height": 0,
"rotation": 180,
"origin": [
0,
0,
0
],
"direction": [
0,
1,
0
],
"originAlignment": "centerMiddle"
},
"inputs": {
"origin": {
"connections": [
{
"node": "vectorXyz2",
"output": "result",
"data": {}
}
]
}
},
"position": [
1007,
304
]
},
"getValueOnProp": {
"id": "getValueOnProp",
"name": "bitbybit.json.getValueOnProp",
"customName": "get value on prop",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"property": "compound"
},
"inputs": {
"json": {
"connections": [
{
"node": "textWithUrl",
"output": "result",
"data": {}
}
]
}
},
"position": [
1387,
306
]
},
"getWires": {
"id": "getWires",
"name": "bitbybit.occt.shapes.wire.getWires",
"customName": "get wires",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"shape": {
"connections": [
{
"node": "getValueOnProp",
"output": "result",
"data": {}
}
]
}
},
"position": [
1768,
305
]
},
"shapeToDxfPaths": {
"id": "shapeToDxfPaths",
"name": "bitbybit.occt.io.shapeToDxfPaths",
"customName": "shape to dxf paths",
"async": true,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"angularDeflection": 0.1,
"curvatureDeflection": 0.1,
"minimumOfPoints": 2,
"uTolerance": 1e-9,
"minimumLength": 1e-7,
"exactCurves": true
},
"inputs": {
"shape": {
"connections": [
{
"node": "makeCompound",
"output": "result",
"data": {}
}
]
}
},
"position": [
3602,
301
]
},
"dxfPathsWithLayer": {
"id": "dxfPathsWithLayer",
"name": "bitbybit.occt.io.dxfPathsWithLayer",
"customName": "dxf paths with layer",
"async": true,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"layer": "Bitbybit",
"color": "#002afa",
"lineType": "continuous"
},
"inputs": {
"paths": {
"connections": [
{
"node": "shapeToDxfPaths",
"output": "result",
"data": {}
}
]
},
"color": {
"connections": [
{
"node": "hexColor",
"output": "result",
"data": {}
}
]
}
},
"position": [
4143,
883
]
},
"dxfCreate": {
"id": "dxfCreate",
"name": "bitbybit.occt.io.dxfCreate",
"customName": "dxf create",
"async": true,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"colorFormat": "aci",
"acadVersion": "AC1015",
"curveTolerance": 0.01,
"fileName": "bitbybit-dev.dxf",
"tryDownload": true
},
"inputs": {},
"position": [
5324,
1765
]
},
"makeCompound": {
"id": "makeCompound",
"name": "bitbybit.occt.shapes.compound.makeCompound",
"customName": "make compound",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"shapes": {
"connections": [
{
"node": "createList",
"output": "list",
"data": {}
}
]
}
},
"position": [
3226,
302
]
},
"fillet2d": {
"id": "fillet2d",
"name": "bitbybit.occt.fillets.fillet2d",
"customName": "fillet 2d",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"radius": 0.05
},
"inputs": {
"shape": {
"connections": [
{
"node": "flatten",
"output": "result",
"data": {}
}
]
}
},
"position": [
2488,
302
]
},
"flatten": {
"id": "flatten",
"name": "bitbybit.lists.flatten",
"customName": "flatten",
"async": false,
"drawable": false,
"data": {
"nrLevels": 1
},
"inputs": {
"list": {
"connections": [
{
"node": "getWires",
"output": "result",
"data": {}
}
]
}
},
"position": [
2125,
344
]
},
"createList": {
"id": "createList",
"name": "bitbybit.lists.createList",
"customName": "create list",
"async": false,
"drawable": false,
"data": {},
"inputs": {
"listElements": {
"connections": [
{
"node": "fillet2d",
"output": "result",
"data": {}
}
]
}
},
"position": [
2862,
342
]
},
"createList2": {
"id": "createList2",
"name": "bitbybit.lists.createList",
"customName": "create list",
"async": false,
"drawable": false,
"data": {},
"inputs": {
"listElements": {
"connections": [
{
"node": "dxfPathsWithLayer",
"output": "result",
"data": {}
},
{
"node": "dxfPathsWithLayer2",
"output": "result",
"data": {}
},
{
"node": "dxfPathsWithLayer3",
"output": "result",
"data": {}
}
]
}
},
"position": [
4834,
1790
]
},
"drawAnyAsync": {
"id": "drawAnyAsync",
"name": "bitbybit.draw.drawAnyAsync",
"customName": "draw any async",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"entity": {
"connections": [
{
"node": "fillet2d",
"output": "result",
"data": {}
}
]
},
"options": {
"connections": [
{
"node": "optionsOcctShapeSimple",
"output": "result",
"data": {}
}
]
}
},
"position": [
3176,
755
]
},
"optionsOcctShapeSimple": {
"id": "optionsOcctShapeSimple",
"name": "bitbybit.draw.optionsOcctShapeSimple",
"customName": "options occt shape simple",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"precision": 0.01,
"drawFaces": false,
"faceColour": "#000000",
"drawEdges": true,
"edgeColour": "#ffffff",
"edgeWidth": 5,
"drawTwoSided": true,
"backFaceColour": "#0000ff",
"backFaceOpacity": 1
},
"inputs": {
"edgeColour": {
"connections": [
{
"node": "hexColor",
"output": "result",
"data": {}
}
]
}
},
"position": [
2684,
990
]
},
"hexColor": {
"id": "hexColor",
"name": "bitbybit.color.hexColor",
"customName": "hex color",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"color": "#ffa200"
},
"inputs": {},
"position": [
2292,
1404
]
},
"textWithUrl2": {
"id": "textWithUrl2",
"name": "bitbybit.advanced.text3d.createWithUrl",
"customName": "text with url",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"text": "CAD Power",
"fontUrl": "https://git-cdn.bitbybit.dev/latest/fonts/Tektur/Tektur-Bold.ttf",
"fontSize": 1,
"height": 0,
"rotation": 180,
"origin": [
0,
0,
0
],
"direction": [
0,
1,
0
],
"originAlignment": "centerMiddle"
},
"inputs": {
"origin": {
"connections": [
{
"node": "vectorXyz",
"output": "result",
"data": {}
}
]
}
},
"position": [
1020,
1589
]
},
"vectorXyz": {
"id": "vectorXyz",
"name": "bitbybit.vector.vectorXYZ",
"customName": "vector xyz",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"x": 0,
"y": 0,
"z": -2
},
"inputs": {},
"position": [
633,
1780
]
},
"getValueOnProp2": {
"id": "getValueOnProp2",
"name": "bitbybit.json.getValueOnProp",
"customName": "get value on prop",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"property": "compound"
},
"inputs": {
"json": {
"connections": [
{
"node": "textWithUrl2",
"output": "result",
"data": {}
}
]
}
},
"position": [
1398,
1589
]
},
"getWires2": {
"id": "getWires2",
"name": "bitbybit.occt.shapes.wire.getWires",
"customName": "get wires",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"shape": {
"connections": [
{
"node": "getValueOnProp2",
"output": "result",
"data": {}
}
]
}
},
"position": [
1777,
1583
]
},
"drawAnyAsync2": {
"id": "drawAnyAsync2",
"name": "bitbybit.draw.drawAnyAsync",
"customName": "draw any async",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"entity": {
"connections": [
{
"node": "getWires2",
"output": "result",
"data": {}
}
]
},
"options": {
"connections": [
{
"node": "optionsOcctShapeSimple2",
"output": "result",
"data": {}
}
]
}
},
"position": [
2700,
1849
]
},
"hexColor2": {
"id": "hexColor2",
"name": "bitbybit.color.hexColor",
"customName": "hex color",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"color": "#cc80ff"
},
"inputs": {},
"position": [
1888,
2497
]
},
"optionsOcctShapeSimple2": {
"id": "optionsOcctShapeSimple2",
"name": "bitbybit.draw.optionsOcctShapeSimple",
"customName": "options occt shape simple",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"precision": 0.01,
"drawFaces": false,
"faceColour": "#000000",
"drawEdges": true,
"edgeColour": "#ffffff",
"edgeWidth": 3,
"drawTwoSided": true,
"backFaceColour": "#0000ff",
"backFaceOpacity": 1
},
"inputs": {
"edgeColour": {
"connections": [
{
"node": "hexColor2",
"output": "result",
"data": {}
}
]
}
},
"position": [
2309,
2012
]
},
"dxfPathsWithLayer2": {
"id": "dxfPathsWithLayer2",
"name": "bitbybit.occt.io.dxfPathsWithLayer",
"customName": "dxf paths with layer",
"async": true,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"layer": "CAD Power",
"color": "#002afa",
"lineType": "continuous"
},
"inputs": {
"color": {
"connections": [
{
"node": "hexColor2",
"output": "result",
"data": {}
}
]
},
"paths": {
"connections": [
{
"node": "shapeToDxfPaths2",
"output": "result",
"data": {}
}
]
}
},
"position": [
4111,
1749
]
},
"shapeToDxfPaths2": {
"id": "shapeToDxfPaths2",
"name": "bitbybit.occt.io.shapeToDxfPaths",
"customName": "shape to dxf paths",
"async": true,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"angularDeflection": 0.1,
"curvatureDeflection": 0.1,
"minimumOfPoints": 2,
"uTolerance": 1e-9,
"minimumLength": 1e-7,
"exactCurves": true
},
"inputs": {
"shape": {
"connections": [
{
"node": "makeCompound2",
"output": "result",
"data": {}
}
]
}
},
"position": [
3327,
1575
]
},
"makeCompound2": {
"id": "makeCompound2",
"name": "bitbybit.occt.shapes.compound.makeCompound",
"customName": "make compound",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"shapes": {
"connections": [
{
"node": "getWires2",
"output": "result",
"data": {}
}
]
}
},
"position": [
2954,
1577
]
},
"vectorXyz2": {
"id": "vectorXyz2",
"name": "bitbybit.vector.vectorXYZ",
"customName": "vector xyz",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"x": 0,
"y": 0,
"z": 2.5
},
"inputs": {},
"position": [
567,
494
]
},
"hexagonsInGrid": {
"id": "hexagonsInGrid",
"name": "bitbybit.occt.shapes.wire.hexagonsInGrid",
"customName": "hexagons in grid",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"width": 15,
"height": 2,
"nrHexagonsInWidth": 40,
"nrHexagonsInHeight": 10,
"flatTop": true,
"extendTop": false,
"extendBottom": false,
"extendLeft": false,
"extendRight": false
},
"inputs": {
"scalePatternWidth": {
"connections": [
{
"node": "parse",
"output": "result",
"data": {}
}
]
},
"scalePatternHeight": {
"connections": [
{
"node": "parse",
"output": "result",
"data": {}
}
]
},
"inclusionPattern": {
"connections": [
{
"node": "parse2",
"output": "result",
"data": {}
}
]
}
},
"position": [
1198,
2944
]
},
"parse": {
"id": "parse",
"name": "bitbybit.json.parse",
"customName": "parse",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"text": "[0.8,0.3]"
},
"inputs": {},
"position": [
678,
3243
]
},
"parse2": {
"id": "parse2",
"name": "bitbybit.json.parse",
"customName": "parse",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"text": "[true, true, false]"
},
"inputs": {},
"position": [
678,
3512
]
},
"makeCompound3": {
"id": "makeCompound3",
"name": "bitbybit.occt.shapes.compound.makeCompound",
"customName": "make compound",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"shapes": {
"connections": [
{
"node": "hexagonsInGrid",
"output": "result",
"data": {}
}
]
}
},
"position": [
1880,
2944
]
},
"dxfPathsWithLayer3": {
"id": "dxfPathsWithLayer3",
"name": "bitbybit.occt.io.dxfPathsWithLayer",
"customName": "dxf paths with layer",
"async": true,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"layer": "Hexagons",
"color": "#002afa",
"lineType": "continuous"
},
"inputs": {
"paths": {
"connections": [
{
"node": "shapeToDxfPaths3",
"output": "result",
"data": {}
}
]
},
"color": {
"connections": [
{
"node": "hexColor3",
"output": "result",
"data": {}
}
]
}
},
"position": [
4142,
2331
]
},
"drawGridMesh": {
"id": "drawGridMesh",
"name": "bitbybit.draw.drawGridMesh",
"customName": "draw grid mesh",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"width": 400,
"height": 400,
"subdivisions": 10,
"majorUnitFrequency": 10,
"minorUnitVisibility": 0.45,
"gridRatio": 0.5,
"opacity": 0.5,
"backFaceCulling": false,
"mainColor": "#ffffff",
"secondaryColor": "#ffffff"
},
"inputs": {},
"position": [
1204,
3994
]
},
"shapeToDxfPaths3": {
"id": "shapeToDxfPaths3",
"name": "bitbybit.occt.io.shapeToDxfPaths",
"customName": "shape to dxf paths",
"async": true,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"angularDeflection": 0.1,
"curvatureDeflection": 0.1,
"minimumOfPoints": 2,
"uTolerance": 1e-9,
"minimumLength": 1e-7,
"exactCurves": true
},
"inputs": {
"shape": {
"connections": [
{
"node": "makeCompound3",
"output": "result",
"data": {}
}
]
}
},
"position": [
2925,
2682
]
},
"optionsOcctShapeSimple3": {
"id": "optionsOcctShapeSimple3",
"name": "bitbybit.draw.optionsOcctShapeSimple",
"customName": "options occt shape simple",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"precision": 0.01,
"drawFaces": false,
"faceColour": "#000000",
"drawEdges": true,
"edgeColour": "#80ff00",
"edgeWidth": 3,
"drawTwoSided": true,
"backFaceColour": "#0000ff",
"backFaceOpacity": 1
},
"inputs": {
"edgeColour": {
"connections": [
{
"node": "hexColor3",
"output": "result",
"data": {}
}
]
}
},
"position": [
2749,
4038
]
},
"drawAnyAsync3": {
"id": "drawAnyAsync3",
"name": "bitbybit.draw.drawAnyAsync",
"customName": "draw any async",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"entity": {
"connections": [
{
"node": "makeCompound3",
"output": "result",
"data": {}
}
]
},
"options": {
"connections": [
{
"node": "optionsOcctShapeSimple3",
"output": "result",
"data": {}
}
]
}
},
"position": [
3236,
3876
]
},
"hexColor3": {
"id": "hexColor3",
"name": "bitbybit.color.hexColor",
"customName": "hex color",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"color": "#58ff42"
},
"inputs": {},
"position": [
2084,
4019
]
}
},
"modules": {}
}

Breaking Down the Process​

Our example creates three distinct layers, each serving a different purpose and demonstrating various aspects of DXF export. Let's walk through what's happening in the code and why each step matters.

Creating and Refining Text Geometry​

The first step is generating 3D text using a custom font loaded from a URL. We create two text strings at different heights along the Z-axis to keep them visually separated. The text generation returns a compound shape, but for DXF export we need the individual wire elements that define the letter outlines. This is where the getWires function comes in, extracting each character's edge geometry into separate wire objects.

For the first text "DXF @ bitbybit.dev", we apply a 2D fillet operation to each wire. Filleting rounds the sharp corners of the letters, giving them a softer, more refined appearance. This is particularly useful when you're preparing designs for fabrication processes that struggle with sharp internal corners, or simply when you want a more polished aesthetic. The fillet radius of 0.05 units creates subtle curves that smooth out the geometry without dramatically altering the character shapes.

The second text "CAD Power" is left unfilleted, preserving the crisp, angular nature of the original font. This contrast between the two text styles demonstrates how you can treat different elements differently within the same DXF file. After processing, both sets of wires are recombined into compound shapes, preparing them for the conversion to DXF format.

Building Decorative Patterns​

The hexagonal grid adds visual interest and shows how pattern-based geometry works with DXF export. The hexagonsInGrid function generates an array of hexagons based on several parameters that control their size, distribution, and appearance. The scale patterns determine how hexagons vary in size across the grid, while the inclusion pattern controls which hexagons actually appear, creating a rhythmic visual pattern.

This kind of parametric pattern generation is where BitByBit really shines compared to traditional CAD. Instead of manually drawing dozens of hexagons, you define the rules and let the algorithm generate the geometry. When you need to adjust the design, you simply change the parameters rather than redrawing everything.

Converting to DXF Paths​

The conversion from OCCT shapes to DXF paths is handled by the shapeToDxfPaths function. It looks at the shape along the Y axis, so a shape lying on the ground plane keeps its size, and it keeps every curve exact: lines and arcs become polylines with bulges, whole circles circles, flat ellipses ellipses, and B-splines, Bezier curves and tilted circles splines. Curves that have no exact form, such as offset curves, become cubic splines within the curvature deflection.

Set exactCurves to false to trace every curve that is not a line or a circle as points instead, for software that reads polylines only. The angular deflection, the curvature deflection and the minimum number of points then decide how closely those points follow the curve; 0.1 is a good balance for most work.

Organizing Layers and Colors​

DXF files use layers to organize geometry, similar to how you might use layers in graphics software or other CAD programs. Each layer has a name and can have its own color, making it easy to control visibility and organize different aspects of your design. In our example, we create three layers: "Bitbybit" for the filleted text in orange, "CAD Power" for the sharp text in purple, and "Hexagons" for the decorative pattern in blue.

The layer organization is crucial when the DXF file is opened in other CAD software. Users can turn layers on and off, change their properties, or work with different elements independently. This is particularly important for manufacturing workflows where different layers might represent different cutting depths, tool paths, or assembly components.

Generating the Final File​

The final step brings everything together using the dxfCreate function. It takes all your layer definitions, combines them into a proper DXF structure, and generates the file. The tryDownload parameter automatically triggers a download in your browser, making it easy to immediately save and use the file. The resulting DXF can be opened in virtually any CAD program, where you'll see your three layers properly organized with their assigned colors and names.

For an SVG file of the same shapes, bitbybit.occt.io.svgLayer puts them on a layer with a colour and a line type, and bitbybit.occt.io.svgCreate draws the layers into one file: each layer becomes a group that Inkscape reads as a layer; arcs and ellipses stay exact SVG arcs and unweighted splines of degree three or lower exact Bezier curves, while weighted (rational) splines, a circle seen at an angle among them, and splines of a higher degree become cubic curves within the tolerance; and with a unit the file has its true size in millimetres, centimetres or inches, ready for laser cutting software.

Practical Applications and Considerations​

This workflow opens up numerous possibilities for integrating Bitbybit into broader design and manufacturing pipelines. You might generate custom signage with parametric text and decorative elements, create intricate laser-cut patterns that would be tedious to draw manually, or export architectural details for documentation. The key advantage is that everything remains parametric until the moment of export, meaning you can iterate rapidly on your designs.

When working with DXF export, keep in mind that the format is fundamentally 2D. While Bitbybit works in 3D space, the DXF conversion projects your geometry into a flat representation. This is why we extract wires rather than solid faces - we're interested in the edge geometry that defines shapes in 2D. If you need to represent 3D objects you should better use STEP, IGES or STL files.

Each part can also carry a line type: dashed, hidden, center or dotted draw its lines broken, with dashes scaled to the drawing, as DXF line types and as SVG dash patterns. To draw what a view of a 3D shape sees, with hidden edges on a layer of their own, use saveShapeDxf or saveShapeSvg.

Colours and File Versions​

Two export options change how the file behaves in whatever opens it.

Colours do not round-trip unless you ask for true colour​

The default colour format is ACI, AutoCAD's palette of 255 numbered colours. Your colour is matched to the nearest of them, so the colour you get back out is close to what you asked for rather than identical. Black and white both become colour 7, which CAD programs draw black on a light background and white on a dark one, so the drawing stays visible either way.

Choose truecolor if you need exact colours. The file then carries your exact colour beside the nearest palette entry, which older software falls back to. It needs AC1015.

The version​

AC1015, AutoCAD 2000, is the default. It keeps every spline and ellipse exact, can state the drawing's unit so it opens at true size, and opens in every current CAD program.

AC1009, AutoCAD R12, is for old software and machine controllers that read nothing newer. R12 has no splines or ellipses, so they are written as polylines within curveTolerance, never finer than a millionth of the drawing's larger side. It has no place for a unit either, so a unit given with AC1009 is refused with an error that says to write AC1015.

If a DXF you exported will not open in an old program, writing AC1009 is the first thing to try.

How other programs read these files​

Every kind of curve these functions write, as DXF and as SVG, is opened by other programs and measured against the model, and so are drawings of shapes from a left-handed BabylonJS scene, a right-handed one, ThreeJS and PlayCanvas. The DXF files pass the audit of ezdxf, a library that checks DXF structure, with nothing to report, and FreeCAD, LibreCAD, Chrome and Blender each show the curves where the model has them.

A few programs do not read everything a DXF file may hold, which is worth knowing when a drawing looks wrong in one of them and right in another:

ProgramWhat it does not read
FreeCAD 1.1Draws an arc of an ellipse as the whole ellipse, lays a tilted circle, arc or ellipse flat, and leaves the closing side off a closed polyline in an AC1009 file.
LibreCADDraws every spline as if its knots were evenly spaced, leaves out splines with weights and splines above degree three, and, being a 2D program, lays tilted curves flat.
Blender 5.2 (SVG)Sizes a drawing given in inches 25.4 times too large, and bends a quadratic curve slightly off its line.

Which version suits a program follows from the table. LibreCAD shows a spline faithfully only as the polyline AC1009 writes for it, while FreeCAD reads AC1015 best, since the closed polylines of AC1009 lose their closing side there.

Reading DXF Files​

A DXF file from AutoCAD, LibreCAD, QCAD or any other program can come back in as geometry. bitbybit.occt.io.loadDxf reads it into one compound of exact wires. Lines, arcs, circles, ellipses, polylines with their bulges and splines keep their exact shapes, splines given only by fit points are interpolated through them, and block inserts are expanded with their position, rotation, scale and arrays. Entities whose ends meet within joinTolerance join into one wire, in whatever order and direction the file lists them, so an outline drawn as separate lines comes back as one closed wire. joinTolerance may be up to 0.001, or a hundredth of what the drawing spans when that is more.

const drawing = await bitbybit.occt.io.loadDxf({ dxf: dxfText, makeFaces: true, unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
const plate = await bitbybit.occt.operations.extrude({ shape: drawing, direction: [0, 3, 0] });

With makeFaces, closed outlines that lie flat become faces, an outline inside another cutting a hole in it, ready to extrude into a plate. The drawing lands on the ground plane as it looks from above, X to the right and its Y running up the view: along +Z in a left-handed engine, such as the editors' BabylonJS scene, and along -Z in a right-handed one, such as ThreeJS or PlayCanvas. That is the way shapeToDxfPaths reads a flat shape, so an outline you wrote with dxfCreate reads back where it was, and a top view saved with bitbybit.occt.io.saveShapeDxf reads back under the shape it shows. This holds for every script made on bitbybit.dev today, and in an app on the npm packages that sets conventions: 1. unit scales the drawing from the unit the file states; a file that states none is read as drawn. dxf takes the file's text, or a File or Blob from a file picker.

Scripts made earlier

A script saved before scripts followed the engine, and an app that leaves conventions out, lay every drawing with its Y along +Z, in any engine. They draw a view with saveShapeDxf the way its frame looks at the shape, so a top view puts +Z at the bottom of the sheet and reads back mirrored front to back; bitbybit.occt.transforms.mirrorAlongNormal with origin [0, 0, 0] and normal [0, 0, 1] puts a top view taken from the origin back where it was. Drop that mirror once the script is updated.

bitbybit.occt.io.loadDxfStructured reads the same file into one shape per layer, colour and line type, each with its layer name, colour and line type, so you can extrude the outlines on a cut layer and engrave the lines on another. Its warnings say what the file held that was not read: text, dimensions, hatches, entities on frozen or switched-off layers (read them with includeHiddenLayers), paper space, and what a very large file held past the size the reader builds from a file of its length.

Without a kernel, bitbybit.io.dxf.dxfRead reads a file into the same layered paths dxfCreate writes, every curve exact, which suits inspecting or editing a drawing as data, or writing it again as SVG with bitbybit.io.svg.svgCreate. Splines given only by fit points need a kernel to interpolate them, so it leaves those out and says so in its warnings. It takes the file's text or its bytes; bytes of an older file that are not UTF-8 are read in the code page the file's header names, as loadDxf reads them.

bitbybit.io.svg.svgRead reads an SVG file into the same model: each Inkscape layer becomes a layer, each stroke colour (or fill, when there is no stroke) a colour and each dash pattern a line type, with lines, arcs and Bezier curves read exactly and Y turned up. To go from one format to the other in one call, bitbybit.io.drawing.svgToDxf and bitbybit.io.drawing.dxfToSvg read one file and write the other, and return the reader's warnings beside the new file's text.

const fromSvg = bitbybit.io.drawing.svgToDxf({ svg: svgText, unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
const fromDxf = bitbybit.io.drawing.dxfToSvg({ dxf: dxfText });

A drawing can also be made without any shape. bitbybit.io.drawing builds the same model piece by piece, for any format: lineSegment, arcSegment, circleSegment, polylineSegment (with bulges for arcs between its points), ellipseSegment and splineSegment make segments, path joins segments into one path, and part puts paths on a layer with a colour and a line type. bitbybit.io.dxf.dxfCreate writes the parts as DXF and bitbybit.io.svg.svgCreate as SVG, so a laser cutter's cut and engrave layers can be drawn straight from numbers. bitbybit.io.svg.pathData gives one path as the text of an SVG path element's d attribute, for a page that draws the outline itself.

const outline = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
const hole = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
const cut = bitbybit.io.drawing.part({ layer: "cut", color: "#ff0000", paths: [{ segments: [outline] }, { segments: [hole] }] });
const svg = bitbybit.io.svg.svgCreate({ parts: [cut], unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });

Scripts written before bitbybit.io.drawing existed call the same builders on bitbybit.io.dxf (lineSegment, arcSegment, circleSegment, polylineSegment, ellipseSegment, splineSegment, path and pathsPart). They still work, but they are deprecated and leave in the next major version.

Conclusion​

DXF export represents an important bridge between Bitbybit's parametric 3D environment and the established world of 2D CAD. By mastering this workflow, you gain the ability to take your parametric designs and deliver them in a format that's universally understood across the manufacturing and design industries. The combination of text generation, geometric processing, pattern creation, and organized layer output demonstrates the power of having a complete toolchain within a single environment.

As you explore DXF export in your own projects, remember that the techniques shown here are building blocks you can combine in countless ways. Try experimenting with different shapes, varying the precision parameters to see their effect, or creating complex layer hierarchies for sophisticated drawings. The parametric nature of Bitbybit means you can always refine and regenerate your exports until they're exactly right for your needs.