Skip to main content
Inspiring
November 30, 2021
Answered

How to Script Exporting Multiple Page PDFs to DXF files

  • November 30, 2021
  • 3 replies
  • 3369 views

Hello, I anyone knows how to do this, I am looking for some assistance with making a script that will

 

1. Export Multipage PDF to an AutoCAD Version 2007/2008/2009 DXF file
2. Add a Suffix to the File Name of  "-1" or "_1" that corresponds to the Page or Artboard Number

 

Any Assistance would be greatly appreciated!

Thank you 🙂

 

This topic has been closed for replies.
Correct answer femkeblanco

@femkeblanco   Thank you!  Do you know where I can place that within my existing script to output a DXF file for each Artboard?


See if this works for you.  If so, you can use the path your script creates as the arguement of the File() constructor. 

 

var doc = app.activeDocument;
var ABs = doc.artboards;
for (var i = 0; i < ABs.length; i++) {
    app.selection = null;
    ABs.setActiveArtboardIndex(i);
    doc.selectObjectsOnActiveArtboard();
    var file1 = new File(app.activeDocument.path + "/file" + i + ".dxf");
    var CAD = new ExportOptionsAutoCAD();
    CAD.exportSelectedArtOnly = true;
    CAD.exportFileFormat = AutoCADExportFileFormat.DXF;
    CAD.version = AutoCADCompatibility.AutoCADRelease18;
    app.activeDocument.exportFile(file1, ExportType.AUTOCAD, CAD);
}

 

3 replies

Participant
October 18, 2022

Hello,

I am new to Illustrator scripts. I am trying to make the script you are talking about but I have zero experiance.

I have several PDF files. Each file has 50+ artboards.

I want to open 1 PDF and export all artboards as seperate DXF files.

These are the settings:

AutoCAD Version 2010/2011/2012

scale 1:1 Milimeters

Maximum Editability

Outline Text

 

As I understand, I have to copy paste the script into notepad and save it in *.vbs file format. Then I open Illustrator, open the PDF I want and go to File > Scripts > Other scripts

But everything I try, I always get: "Expected statement" or "Expected end of statement"

 

I can make a small donation for someone who helps me.

renél80416020
Inspiring
October 18, 2022

Bonjour Ivan,

Extension .js (pour JavaSript)

Inspiring
November 30, 2021

I found this here
https://ai-scripting.docsforadobe.dev/jsobjref/ExportOptionsAutoCAD.html#jsobjref-exportoptionsautocad-exportfileformat
and I have no clue how to include it in the script correctly...


// Export DXF Files for AutoCAD 2007/2008/2009

    exportOptionsAutoCAD.exportFileFormat.DXF;    
    AutoCADCompatibility.AutoCADRelease17;
    AutoCADGlobalScaleOption.OriginalSize;
 
(I don't need the AI files but I am working with what I have)
m1b
Community Expert
Community Expert
November 30, 2021

Also, see @renél80416020's answer here.

Inspiring
November 30, 2021

Okay so I was able to create  the Saving with a Suffix piece... but it is saving as an AI File... is there a way I can adjust this to Export as an  AutoCAD Version 2007/2008/2009 DXF file?

 

Thank you for looking!  🙂

 

var doc = app.activeDocument;
var boards = doc.artboards;
var strEnter = doc.name; //alert(strEnter);
var soNum = strEnter.slice(0,7);
var myNum = 1;
var arrayCount;
var arrayLength;
var arr;
var sc = "/";	
var folderPrefix = sc + sc + "idp-fs-02" + sc + "Graphics" + sc;
var searchString1 = /\d{7}/;
var searchString2 = /(\d)(\d)(\d)/;

if (strEnter != null && searchString1.test(strEnter) === true) {
    var strEnter = strEnter.replace(/^0+/, '');  
    var str = null;
    var arr = strEnter.match (searchString2);
    var folder1 = shorten (arr[1], first) +"-"+ shorten (arr[1], last) + sc;
    var folder2 = shorten (arr[1]+arr[2], first) +"-"+ shorten (arr[1]+arr[2], last) + sc;
    var folder3 = shorten (arr[1]+arr[2]+arr[3], first) +"-"+ shorten (arr[1]+arr[2]+arr[3], last) + sc;
    var folderString = (folderPrefix + folder3); 

        function shorten (strt1, num) {
            str = strt1 + num;
            return str = str.slice(0, 7);
            }
 
            activeFolder = new Folder (folderString);
if (activeFolder.exists === false) {
    activeFolder.create();
    }

// loop through all artboards, make each one active and render before moving onto the next
for(var i = 0; i < boards.length; i++) {
    doc.artboards.setActiveArtboardIndex(i);

    var saveOptions = new IllustratorSaveOptions();
    var aiDoc = new File(folderString + strEnter +"_"+(i+1).toString()); //alert(aiDoc);
    saveOptions.saveMultipleArtboards = true;
    saveOptions.artboardRange = (i+1).toString();
    doc.saveAs(aiDoc, saveOptions);
    }   
}

 

femkeblanco
Legend
November 30, 2021

To export as AutoCAD (I've just made a guess that AutoCADRelease21 corresponds to AutoCAD 2007):

var file1 = new File(app.activeDocument.path);
var CAD = new ExportOptionsAutoCAD();
CAD.exportFileFormat = AutoCADExportFileFormat.DXF;
CAD.version = AutoCADCompatibility.AutoCADRelease21;
app.activeDocument.exportFile(file1, ExportType.AUTOCAD, CAD);

 

Inspiring
December 1, 2021

@femkeblanco   Thank you!  Do you know where I can place that within my existing script to output a DXF file for each Artboard?