• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

how to get a specific function to repeat through all artboards in a document?

Participant ,
Aug 12, 2017 Aug 12, 2017

Copy link to clipboard

Copied

Greetings,

with my limited knowledge I've made (or rather clumsily hacked together) a script that I use for exporting proof pdf's from illustrator that will simply draw a rectangle with a thin stroke around my document and save a pdf, then delete the rectangle and resave the .AI file (this last part is just to speed things up, so I can keep working on my ai file afterwards).

This all works perfectly fine on a document with only one artboard, however the whole thing falls apart if I want to make a multipage pdf with more than one artboards.
I need it to do the same actions but instead of just drawing the rectangle once I want it to draw it around every artboard in my document.
I realise this is probably easily achieved by looping through my artboards I just don't know how to go about it.

I've included the script I'm using in full below, it probably has quite a few redundant bits here or there, but hopefully you can make sense of it 

var idoc = app.activeDocument; 

var width = idoc.width;

var height = idoc.height;

newCMYKColor = new CMYKColor;

newCMYKColor.black = 100;

newCMYKColor.cyan = 0;

newCMYKColor.magenta = 0;

newCMYKColor.yellow = 0;   

var CurrentPath = activeDocument.path;

var folderPDF = Folder(CurrentPath);

if(!folderPDF.exists) folderPDF.create();

var docName = app.activeDocument.name.match(/^.*[^.ai]/i);

var myDoc = app.activeDocument.name.match();

        if (folderPDF) {

            if ( app.documents.length > 0 ) {

                var destFile = new File(folderPDF + '/' + docName + "_HR");

                var sourceDoc = app.activeDocument;

               

                targetFile = getNewName();

                targetFileAI = getNewNameAI();

                pdfSaveOpts = getPDFOptions( );

                illustratorSaveOpts = getAIOptions();

   

                var rectangle = idoc.pathItems.rectangle(0, 0, width, height);

                rectangle.filled = false;

                rectangle.strokeColor = newCMYKColor;

                rectangle.strokeWidth = 1;

                sourceDoc.saveAs( targetFile, pdfSaveOpts );

                rectangle.remove()    

                sourceDoc.saveAs( targetFileAI, illustratorSaveOpts );

               

                }

            }

       

function getNewName()

{

    var ext, docName, newName, saveInFile, docName;

    docName = sourceDoc.name;

    ext = '_HR_CMYK_PROOF_nobleed.pdf';

    newName = "";       

    for ( var i = 0 ; docName != "." ; i++ )

    {

        newName += docName;

    }

    newName += ext;

    saveInFile = new File( folderPDF + '/' + newName );   

    return saveInFile;

}

function getNewNameAI()

{

    saveInFileAI = new File( folderPDF + '/' + sourceDoc.name );

    return saveInFileAI;

}

function getPDFOptions()

{

    var pdfSaveOpts = new PDFSaveOptions();

    pdfSaveOpts.pDFPreset = "Inferno Print File (no bleed)";

    return pdfSaveOpts;

}

function getAIOptions()

{

    var illustratorSaveOpts = new IllustratorSaveOptions();

    illustratorSaveOpts.pdfCompatible = false;

    return illustratorSaveOpts;

}

TOPICS
Scripting

Views

808

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

Enthusiast , Aug 13, 2017 Aug 13, 2017

Not tested yet, but it should work

var idoc = app.activeDocument;

newCMYKColor = new CMYKColor;

newCMYKColor.black = 100;

newCMYKColor.cyan = 0;

newCMYKColor.magenta = 0;

newCMYKColor.yellow = 0;

var CurrentPath = activeDocument.path;

var folderPDF = Folder(CurrentPath);

if (!folderPDF.exists) folderPDF.create();

var docName = app.activeDocument.name.match(/^.*[^.ai]/i);

// "/^.*[^.ai]/" is strange, it will match all of the name.

// so above code =

// var docName = app.activeDocument.name;

// maybe you sho

...

Votes

Translate

Translate
Adobe
Enthusiast ,
Aug 13, 2017 Aug 13, 2017

Copy link to clipboard

Copied

Not tested yet, but it should work

var idoc = app.activeDocument;

newCMYKColor = new CMYKColor;

newCMYKColor.black = 100;

newCMYKColor.cyan = 0;

newCMYKColor.magenta = 0;

newCMYKColor.yellow = 0;

var CurrentPath = activeDocument.path;

var folderPDF = Folder(CurrentPath);

if (!folderPDF.exists) folderPDF.create();

var docName = app.activeDocument.name.match(/^.*[^.ai]/i);

// "/^.*[^.ai]/" is strange, it will match all of the name.

// so above code =

// var docName = app.activeDocument.name;

// maybe you should use /^.*(?=\.ai$)/

if (folderPDF) {

    if (app.documents.length > 0) {

        var destFile = new File(folderPDF + '/' + docName + "_HR");

        var sourceDoc = app.activeDocument;

        targetFile = getNewName();

        targetFileAI = getNewNameAI();

        pdfSaveOpts = getPDFOptions();

        illustratorSaveOpts = getAIOptions();

        var artboardRef = sourceDoc.artboards;

        var rectLayer = sourceDoc.layers.add(); // so all rectangles will add to this layers

        // add rect for all artboards

        for (i = 0; i < artboardRef.length; i++) {

            var top = artboardRef.artboardRect[1];

            var left = artboardRef.artboardRect[0];

            var width = artboardRef.artboardRect[2] - artboardRef.artboardRect[0];

            var height = artboardRef.artboardRect[1] - artboardRef.artboardRect[3];

            var rect = docRef.pathItems.rectangle(top, left, width, height);

            rect.filled = false;

            rect.strokeColor = newCMYKColor;

            rect.strokeWidth = 1;

        }

        sourceDoc.saveAs(targetFile, pdfSaveOpts);

        rectLayer.remove(); // remove layer to remove all rectangles

        sourceDoc.saveAs(targetFileAI, illustratorSaveOpts);

    }

}

function getNewName() {

    var ext, docName, newName, saveInFile, docName;

    docName = sourceDoc.name;

    ext = '_HR_CMYK_PROOF_nobleed.pdf';

    newName = "";

    for (var i = 0; docName != "."; i++) {

        newName += docName;

    }

    newName += ext;

    saveInFile = new File(folderPDF + '/' + newName);

    return saveInFile;

}

function getNewNameAI() {

    saveInFileAI = new File(folderPDF + '/' + sourceDoc.name);

    return saveInFileAI;

}

function getPDFOptions() {

    var pdfSaveOpts = new PDFSaveOptions();

    pdfSaveOpts.pDFPreset = "Inferno Print File (no bleed)";

    return pdfSaveOpts;

}

function getAIOptions() {

    var illustratorSaveOpts = new IllustratorSaveOptions();

    illustratorSaveOpts.pdfCompatible = false;

    return illustratorSaveOpts;

}

Votes

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
Participant ,
Aug 13, 2017 Aug 13, 2017

Copy link to clipboard

Copied

LATEST

Thanks heaps Moluapple. This works perfectly

Votes

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