Copy link to clipboard
Copied
Hi,
I have a large batch of files (100+) that all have the same layer structure. The top layer is called 'Guides', the next layer is called 'Object", the next layer is called 'Shadow' and it goes on down through another 5 layers. I'd like to create a script that will select delete certain layers (eg. 'Guides') before I save out a new file as part of an action. I'm coming from a background in Photoshop, where this could all be done in actions, but appears you can't select layers in Illustrator (please correct me if I'm wrong!).
Any help in creating a script would be most appreciated!
Dave
Copy link to clipboard
Copied
app.activeDocument.layers.getByName('guides').remove();
or you could act on all open docs.
for(var i = 0; i < app.documents.length; i++){
app.documents.layers.getByName('guides').remove();
}
the scipt to work on a folder is a bit more work...
Copy link to clipboard
Copied
not ideal but it works...
// Batch remove layer from files
// Qwertyfly
// 17-4-2015
// -------------------- WARNING ------------------------------------------------------------------------------
// this will overwrite files - make sure you have made copies of the files before running
//------------------------------------------------------------------------------------------------------------------
// these variables need to be updated before running
var workingDirectory = '~/Desktop/~~~Crap/tst'; // Add folder to process here
var fileType = 'ai'; // make sure you update the file type here
var layerToRemove = 'guides'; // and here is the layer you wish removed
var reg = new RegExp("\.("+fileType+")$", 'i');
var dir = Folder(workingDirectory);
var files = dir.getFiles(reg);
var log = files.length + ' Files Processed \n';
for(var i = 0; i < files.length; i++){
var file = File(dir + '/' + files.name);
var doc = app.open(file);
try{
app.activeDocument.layers.getByName(layerToRemove).remove();
log += files.name + ' - "'+layerToRemove+'" Layer removed \n';
}
catch(err){
log += files.name + ' - Has no "'+layerToRemove+'" Layer \n';
}
doc.close();
doc = null
}
txtlog = new File(workingDirectory + '/textlog.txt');
var isopen = txtlog.open("w"); //open file for editing
if (isopen)//test file is open
{
txtlog.seek(0,0);
txtlog.write(log);
txtlog.close();
}
Copy link to clipboard
Copied
Wow, thanks for that. I tried the first answer you gave and that worked nicely on individual files, and tomorrow I'll try this.
Thanks very much!
Dave
Copy link to clipboard
Copied
no problem.
make sure you make copies of your files first.
I would hate for it to Bug out and make a mess of anything.
PS. not tested on anything but ai files
Copy link to clipboard
Copied
Line 31 can be changed to:
doc.close( SaveOptions.SAVECHANGES );
to avoid a dialogue box.
Copy link to clipboard
Copied
‌good to know. Thanks.
i Was not getting any dialog box when I was running it.
may be due to only running it from ESTK
Copy link to clipboard
Copied
Hi Dave,
The script work for you? how to run it? i try to run the script on AI 2019 no response....
Please advice
Thanks in advance
Copy link to clipboard
Copied
You need a layer (not an object, not a sublayer) with name: guides.
This layer will be removed. Works in Illu CC 2019 as well.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now