// illustrator-batch-svg-to-dxf.jsx // Free script from LinearAndLoom Icons: https://linearandloomicons.netlify.app/scripts/ // Provided as is. Try it on a copy of your files first. /* SVG to DXF - Adobe Illustrator script ------------------------------------------------------------ Converts every .svg file in a folder to a DXF file for cutting machines, laser cutters and CAD software. HOW TO RUN Illustrator: File > Scripts > Other Script... > choose this file. 1. Pick the folder that contains the .svg files. 2. Pick the folder where the .dxf files should be saved. Units are inches. To use millimetres, change AutoCADUnit.Inches to AutoCADUnit.Millimeters below. Original SVG files are never modified. */ #target illustrator function main() { var inputFolder = Folder.selectDialog("Select folder with SVG files"); if (!inputFolder) return; var outputFolder = Folder.selectDialog("Select folder to save DXF files"); if (!outputFolder) return; var svgFiles = inputFolder.getFiles(function (file) { return file instanceof File && file.name.match(/\.svg$/i); }); if (svgFiles.length === 0) { alert("No SVG files found."); return; } var previousLevel = app.userInteractionLevel; app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; var done = 0, failed = []; for (var i = 0; i < svgFiles.length; i++) { var file = svgFiles[i]; var doc = null; try { doc = app.open(file); // Export as DXF var dxfFile = new File(outputFolder + "/" + file.name.replace(/\.svg$/i, ".dxf")); var dxfOptions = new ExportOptionsAutoCAD(); dxfOptions.exportFileFormat = AutoCADExportFileFormat.DXF; dxfOptions.version = AutoCADCompatibility.AutoCADRelease18; // widely compatible; use AutoCADRelease24 for newest dxfOptions.unit = AutoCADUnit.Inches; // change to Millimeters if that's your unit dxfOptions.exportOption = AutoCADExportOption.MaximumEditability; dxfOptions.convertTextToOutlines = false; // no text in these files dxfOptions.colors = AutoCADColors.TrueColors; dxfOptions.rasterFormat = AutoCADRasterFormat.PNG; doc.exportFile(dxfFile, ExportType.AUTOCAD, dxfOptions); doc.close(SaveOptions.DONOTSAVECHANGES); done++; } catch (e) { // one bad file must not stop the rest failed.push(decodeURI(file.name) + " (" + e + ")"); try { if (doc) { doc.close(SaveOptions.DONOTSAVECHANGES); } } catch (e2) {} } } app.userInteractionLevel = previousLevel; var msg = "SVG to DXF - finished\n\nConverted: " + done; if (failed.length) { msg += "\n\nCould not convert " + failed.length + ":\n" + failed.slice(0, 15).join("\n"); } alert(msg); } main();