batch exporting script SVG to DXF scaling issue
Does anyone have any idea why when I run the following java script my resulting DXF file is the wrong scale? If I do the process manually I get the correct result. Thanks very much
// Define the folder containing the SVG files
var folderPath = Folder.selectDialog("Select the folder with SVG files");
// Check if the folder is valid
if (folderPath != null) {
// Get all SVG files in the folder
var svgFiles = folderPath.getFiles("*.svg");
// Loop through each SVG file
for (var i = 0; i < svgFiles.length; i++) {
var svgFile = svgFiles[i];
// Open the SVG file
var activeDoc = app.open(svgFile);
// Select all objects in the active document
activeDoc.selectObjectsOnActiveArtboard();
// Set the name for the DXF file (same as the SVG file, but with .dxf extension)
var dxfFileName = svgFile.name.replace(".svg", ".dxf");
var dxfFilePath = folderPath.fsName + "/" + dxfFileName;
// Set the export options for DXF
var dxfOptions = new ExportOptionsAutoCAD();
dxfOptions.exportFileFormat = AutoCADExportFileFormat.DXF; // Use DXF format
// Set artwork scale to ensure 1 point = 1 unit
dxfOptions.artworkScale = 1; // 1 point = 1 unit
// Preserve appearance
dxfOptions.preserveAppearance = true;
// Only export selected objects
dxfOptions.selectedOnly = true; // Export only selected art
// Export the selected objects as DXF to the same location
var dxfFile = new File(dxfFilePath);
activeDoc.exportFile(dxfFile, ExportType.AUTOCAD, dxfOptions);
// Close the document without saving changes
activeDoc.close(SaveOptions.DONOTSAVECHANGES);
// Alert the user for each file processed
$.writeln("Processed: " + svgFile.name);
}
// Alert when all SVGs have been exported
alert("All SVG files have been successfully exported as DXF to the same folder!");
} else {
alert("No folder selected. Script canceled.");
}
