Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

Create element at center of artboard, move to next artboard and repeat

$
0
0

Hey All! I've been lurking around here for quite some time and i've always been able to find what i needed. Until now. =)

 

I'm writing a Javascript to create multiple rectangles on the center of the active artboard and then repeat for all remaining artboards. However, i'm getting hung up on how to shift focus to the next artboard. I've read about  "setActiveArtboardIndex();" but whenever i try to use this feature, i get the error "setActiveArtboardIndex(); is not a function".

 

Here's the code i'm working with. Could anyone please tell me how to get the loop to switch to the next artboard before creating the next set of color blocks?

 

 

//Beginning of Script

#target illustrator

if (app.documents.length > 0) {

var docRef = app.activeDocument
}
else {
alert("No Document Open");
}




//Add Color Block Layer


artLayers.locked = true;


function existBlockLayer(layers, name) {
    for (i=0; i<docRef.layers.length; i++){        if (layers[i].name===name) return true;        }    return false;    }          
if (existBlockLayer(docRef.layers,"Color Blocks")) {    var removeLayer = artLayers.getByName("Color Blocks");    removeLayer.locked = false;    removeLayer.remove();    var blockLayer = docRef.layers.add();    blockLayer.name = "Color Blocks"    }
else {    var blockLayer = docRef.layers.add();    blockLayer.name = "Color Blocks"    }


blockLayer.locked = false;






//Get Document Swatches


var swatchList = docRef.swatches;
var artLayers = docRef.layers
var aB = docRef.artboards
var colorList = [];




for(var k=0; k< swatchList.length; k++) {    if (swatchList[k].name.toLowerCase() != "thru-cut" && swatchList[k].name.toLowerCase() != "[registration]"//    && swatchList[k].name.toLowerCase() != "[none]" && swatchList[k].name.toLowerCase() != "cut line"){            colorList.push(swatchList[k].name);           }       }




//Create 1 Color Block per Swatch and Apply Swatch


for (var a=0; a<aB.length; a++) {          var aBLeft = aB[a].artboardRect[0];    var aBRight = aB[a].artboardRect[2]    var aBTop = aB[a].artboardRect[1]    var aBBottom = aB[a].artboardRect[3]        var W = (aBRight/2);    var H = (aBBottom/2);      var posH = (H/2);      var posW = (W/2);    alert(W + " width " + H + " height");     var activeArtboard = aB[a];      //var aBPlus = setActiveArtboardIndex(a);      for(var c=0,len=colorList.length;c<len;c++){        var newBlock = docRef.pathItems.rectangle(posH, posW,10,10);        newBlock.stroked = false;         }      for (var i=0; i < colorList.length; i++) {        docRef.pathItems[i].fillColor=docRef.swatches.getByName(colorList[i]).color;    }
}   
artLayers.locked = false;
blockLayer.zOrder (ZOrderMethod.SENDTOBACK);
blockLayer.locked = true;

 

 

 

 

 

Thanks in advance all!


Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>