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

Batch Remove Guides If they Exists

Community Beginner ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

Hello guys,

I am using Illustrator CC 2017 and I have a bunch of files which may or may not have guides.

After going through various threads, I came up with a script to remove Guides automatically if they exist but somehow it is getting stuck while saving the file.

Here is the javascript

sourceFolder = Folder.selectDialog();

// filesToProcess = sourceFolder.getFiles("*.ai");

var TypeList = prompt("Enter file types to act on","ai,eps,pdf","File Types");  

var reg = new RegExp("\.(" + TypeList.replace(/,/g, '|') + ")$", 'i');  

var filesToProcess = sourceFolder.getFiles(reg);

// Increment through the files

for (i=0; i < filesToProcess.length; i++) {

app.open(filesToProcess);

var myDoc=app.activeDocument;

// Remove Guides

for(var i = myDoc.pathItems.length-1; i >= 0; i--) {

var p = myDoc.pathItems;

if (p.guides == true) {

p.remove();

}

}

// Save

var mySaveOptions = new IllustratorSaveOptions();

mySaveOptions.pdfCompatible = true;

myDoc.saveAs(filesToProcess,mySaveOptions);

myDoc.close();

}

here is the link to the test Illustrator file  https://drive.google.com/open?id=0B8FDkTEOTC4POUNpLXFtSUl0YzQ

it would be really great if someone could help me fix it.

Thanks

TOPICS
Scripting

Views

574

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

Community Expert , Aug 08, 2017 Aug 08, 2017

ca_saurabh02  schrieb

I could have used that but in the folder, there are files that may or may not have the guides so have to loop through them.

No. That's the best reason for using the executeMenuCommand

If guides exists they will delete. If no guides exists - ist's not a problem for the Command.

And your code is not my kind of coding.

But with your syntax you have to define the file name and the place to save. And if the name is the same as your opened file - the existing file wil be overwritten!!

...

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

ca_saurabh02  schrieb

Hello guys,

I am using Illustrator CC 2017 and I have a bunch of files which may or may not have guides.

After going through various threads, I came up with a script to remove Guides automatically if they exist but somehow it is getting stuck while saving the file.

Here is the javascript

...

// Remove Guides

for(var i = myDoc.pathItems.length-1; i >= 0; i--) {

var p = myDoc.pathItems;

if (p.guides == true) {

p.remove();

}

}

...

Instead of loop through all items - better use the following line of code:

app.executeMenuCommand ('clearguide')

Much more better performance.

Have fun

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 ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

I could have used that but in the folder, there are files that may or may not have the guides so have to loop through them.

The Error I am getting while Saving is in this Line myDoc.saveAs(filesToProcess,mySaveOptions);

The error is "Illegal argument - argument 1 - Required value is missing"

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 Expert ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

ca_saurabh02  schrieb

I could have used that but in the folder, there are files that may or may not have the guides so have to loop through them.

No. That's the best reason for using the executeMenuCommand

If guides exists they will delete. If no guides exists - ist's not a problem for the Command.

And your code is not my kind of coding.

But with your syntax you have to define the file name and the place to save. And if the name is the same as your opened file - the existing file wil be overwritten!!!

With your syntax you can do something like this:

sourceFolder = Folder.selectDialog();

// filesToProcess = sourceFolder.getFiles("*.ai");

var TypeList = prompt("Enter file types to act on","ai,eps,pdf","File Types");

var reg = new RegExp("\.(" + TypeList.replace(/,/g, '|') + ")$", 'i');

var filesToProcess = sourceFolder.getFiles(reg);

// Increment through the files

for (i=0; i < filesToProcess.length; i++) {

app.open(filesToProcess);

var myDoc=app.activeDocument;

// Remove Guides

app.executeMenuCommand ('clearguide');

/*

for(var i = myDoc.pathItems.length-1; i >= 0; i--) {

var p = myDoc.pathItems;

if (p.guides == true) {

p.remove();

}

}

*/

var saveFile = File (filesToProcess.path + "/" + filesToProcess.name.replace(reg, "_withoutGuides.ai") );

// Save

var mySaveOptions = new IllustratorSaveOptions();

mySaveOptions.pdfCompatible = true;

myDoc.saveAs(saveFile,mySaveOptions);

myDoc.close();

}

The new saved file will be saved as ai-file with the same name and in the same folder as your original file but with the suffix "_withoutGuides"

Have fun

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 ,
Aug 08, 2017 Aug 08, 2017

Copy link to clipboard

Copied

LATEST

Thank you so much, it worked as I wanted. I am a noob with scripting and have been trying for the whole day.

Thanks again.

Regards

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