Hello William,
One day, I'd like to be in your position where I'm giving back to the community that gave to you ;-) There is a link to the sample file you are requesting.
Also, i ran the script both on my mac & pc, and when I use duplicate method, illustrator freezes.
Dropbox - SampleArt.ai
Thanks a bunch for your help.
well fooey! i knew that while loop would come back to bite me in the rear... I originally had a for loop working backwards to move all of the artwork to the GroupedArt layer, but for some reason it was not moving everything.. So i took the easy route and just made it keep looping until the number of items on the source layer (Art1 for example) was zero. This works great if you're MOVING art.. but if you're duplicating artwork, then the number of items on the source layer will NEVER be zero...
By changing from moveToBeginning() to duplicate(), we created an infinite loop.... my shame shall live on forever, just like that while loop.
give this one a try. I also added some support for unlocking/relocking unhiding/rehiding layers so that you won't get an error if it tries to manipulate a locked/hidden layer, but it will also re-set everything back to the way it was after the art is duplicated. there's probably a better way to do it, but this works just fine. Hope this helps.
function test()
{
var docRef = app.activeDocument;
var layers = docRef.layers;
var swatches = docRef.swatches;
var searchTerms = ["Art1", "Art2", "Art3"];
var stLen = searchTerms.length;
var groupedArtLayer = layers.add();
groupedArtLayer.name = "GroupedArt";
var cyanStrokeColor = new CMYKColor();
cyanStrokeColor.cyan = 100;
cyanStrokeColor.magenta = 0;
cyanStrokeColor.yellow = 0;
cyanStrokeColor.black = 0;
var cyanSwatch = swatches.add();
cyanSwatch.name = "Cyan";
cyanSwatch.color = cyanStrokeColor;
function copyArtToLayer(srcLay, destLay)
{
var reLock = srcLay.locked ? true : false;
var reHide = !srcLay.visible ? true : false;
srcLay.locked = false;
srcLay.visible = true;
var item;
for(var x = srcLay.pageItems.length -1; x>=0;x--)
{
item = srcLay.pageItems;
item.duplicate(destLay);
}
srcLay.locked = reLock ? true : false;
srcLay.visible = reHide ? false : true;
}
var curLay, curLayName, curTerm;
for (var x = layers.length - 1; x > 0; x--)
{
curLay = layers;
curName = curLay.name;
for (var y = 0; y < stLen; y++)
{
curTerm = searchTerms;
if (curName === curTerm)
{
copyArtToLayer(curLay, groupedArtLayer);
}
}
}
docRef.selection = null;
groupedArtLayer.hasSelectedArtwork = true;
docRef.defaultFillColor = swatches["[None]"].color;
docRef.defaultStrokeColor = swatches["Cyan"].color;
}
test();