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

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

548

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

 

Votes

Translate

Translate
Adobe
Advocate ,
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]);

 

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

Copy link to clipboard

Copied

LATEST

Merci! That worked beautifully, thanks so much for your help!

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