How to Script Exporting Multiple Page PDFs to DXF files

Contributor ,
Nov 30, 2021 Nov 30, 2021

Copy link to clipboard

Copied

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 🙂

 

TOPICS
Scripting

Views

210

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Dec 01, 2021 Dec 01, 2021
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 = Au...

Likes

Translate

Translate
Contributor ,
Nov 30, 2021 Nov 30, 2021

Copy link to clipboard

Copied

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);
    }   
}

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 30, 2021 Nov 30, 2021

Copy link to clipboard

Copied

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);

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 01, 2021 Dec 01, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 01, 2021 Dec 01, 2021

Copy link to clipboard

Copied

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);
}

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 02, 2021 Dec 02, 2021

Copy link to clipboard

Copied

@femkeblanco 

 

That did it!!!    I was Looping on the wrong piece of my script and couldn't figure out how to do the individual artboards for export and you solved it in like 12 lines of code!!  

 

In all Sincerity, Thank you!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 02, 2021 Dec 02, 2021

Copy link to clipboard

Copied

LATEST

Glad I could help. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 30, 2021 Nov 30, 2021

Copy link to clipboard

Copied

I found this here
https://ai-scripting.docsforadobe.dev/jsobjref/ExportOptionsAutoCAD.html#jsobjref-exportoptionsautoc...
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)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 30, 2021 Nov 30, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 01, 2021 Dec 01, 2021

Copy link to clipboard

Copied

Bonjour Bryan,

Je peux faire un script pour vous...

René

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 01, 2021 Dec 01, 2021

Copy link to clipboard

Copied

@renél80416020 

 

Thank you!  I can get my Script to do what I need it to do, except it only creates 1 DXF file. 
If I have 3 artboards I need 3 DXF files. 1 for each artboard.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines