Can I make a Script that makes a rectangle sized to each Artboard, only work for the Active Artboard

Community Beginner ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

I'm currently working on a complex Action in Illustrator that segments a print file in a specific way. There are a handful of scripts that I found online that the action runs in order to achieve some things actions aren't currently capable of. One of the scripts I found creates a rectangle sized and positioned for each Artboard within my Document. This nearly fits my needs, but I would like to alter the script so that it only creates a rectangle for the Active Artboard. I tried altering the script myself, but I have basically no idea what I'm doing and all of the attempts I've made to change it have resulted with errors. Could someone with more scripting knowledge possibly tell me if it can be altered to fit my needs, and how to do so. Would be greatly appreciated. Here's the script in question.

 

#target illustrator
var docRef = app.activeDocument;
var artboardRef = docRef.artboards;

for(i=0;i<artboardRef.length;i++){
     var top=artboardRef[i].artboardRect[1];
     var left=artboardRef[i].artboardRect[0];
     var width=artboardRef[i].artboardRect[2]-artboardRef[i].artboardRect[0];
     var height=artboardRef[i].artboardRect[1]-artboardRef[i].artboardRect[3];
     var rect = docRef.pathItems.rectangle (top, left, width, height);
     rect.fillColor = rect.strokeColor = new NoColor();
     }

TOPICS
Scripting

Views

152

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

Enthusiast , Feb 18, 2021 Feb 18, 2021
Bonjour!var docRef = app.activeDocument; var idx = docRef.artboards.getActiveArtboardIndex(); var ab = docRef.artboards[idx]; var rect = ab.artboardRect; app.defaultStroked = true; app.defaultFilled = true; var cadre = docRef.pathItems.rectangle(rect[1],rect[0],rect[2]-rect[0],rect[1]-rect[3]);

Likes

Translate

Translate
Enthusiast ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Bonjour!

var docRef = app.activeDocument;
    var idx  = docRef.artboards.getActiveArtboardIndex();
    var ab  = docRef.artboards[idx];
    var rect = ab.artboardRect;
    app.defaultStroked = true;
    app.defaultFilled = true;
    var cadre = docRef.pathItems.rectangle(rect[1],rect[0],rect[2]-rect[0],rect[1]-rect[3]);

 

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
Community Beginner ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

LATEST

Merci! That worked beautifully, thanks so much for your 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