Highlighted

This is a font change script. Save changes in eps.

Community Beginner ,
Jul 22, 2020

Copy link to clipboard

Copied

Hello.
When I run the jsx script, the eps file is saved as ai.
Where should I fix it to be saved as eps?

I am using cs5.

/*
Replace fonts in all the Illustrator files in a folder
Edit the array at the top to your own substitutions
Find the font names to replace using: https://gist.github.com/2778294
*/

// fonts to replace
var substitutions = [
  ['BellGothic BT', 'Bold',         'Roboto', 'Condensed'],
  ['BellGothic Blk BT', 'Black',    'Roboto', 'Bold Condensed'],
];

//  turn the substitutions into real fonts
var subsRight = [];
var fontCount = textFonts.length;
var subsCount = substitutions.length;
for (var i = 0; i < fontCount; i++) {
  var font = textFonts[i];
  for (var j = 0; j < subsCount; j++) {
    if (substitutions[j][2] == font.family && substitutions[j][3] == font.style) {
      subsRight[j] = font;
    }
  }
}

function getAllFiles(folder) {
  var fileList = [];
  function recurse (folder) {
    var files = folder.getFiles("*.ai");
    for (var i = 0; i < files.length; i++)
      fileList.push(files[i]);

    var folders = folder.getFiles();
    var len = folders.length;
    for (var i = 0; i < len; i++) {
      if (folders[i] instanceof Folder) {
        recurse(folders[i]);
      }
    }
  }
  if (folder != null && folder instanceof Folder)
    recurse(folder);
  return fileList;
}

var sourceFolder = Folder.myDocuments.selectDlg( 'Select the folder with Illustrator files in which you want to replace fonts');
var files = getAllFiles(sourceFolder);

for ( var i = 0; i < files.length; i++ ) {
  var file = files[i];
  var doc = app.open(file);

  // replace the font
  var frames = doc.textFrames;
  for ( var j = 0; j < frames.length; j++ ) {
    var ranges = frames[j].textRanges;
    for ( var k = 0; k < ranges.length; k++ ) {
      var range = ranges[k];
      for (var f = 0; f < subsCount; f++) {
        if (range.characterAttributes.textFont.family == substitutions[f][0] 
          && range.characterAttributes.textFont.style == substitutions[f][1]) {
          range.characterAttributes.textFont = subsRight[f];
        }
      }
    }
  }
  redraw();

  doc.save();
  doc.close();  
}

 

TOPICS
How to, Import and export, Scripting

Views

69

Likes

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

This is a font change script. Save changes in eps.

Community Beginner ,
Jul 22, 2020

Copy link to clipboard

Copied

Hello.
When I run the jsx script, the eps file is saved as ai.
Where should I fix it to be saved as eps?

I am using cs5.

/*
Replace fonts in all the Illustrator files in a folder
Edit the array at the top to your own substitutions
Find the font names to replace using: https://gist.github.com/2778294
*/

// fonts to replace
var substitutions = [
  ['BellGothic BT', 'Bold',         'Roboto', 'Condensed'],
  ['BellGothic Blk BT', 'Black',    'Roboto', 'Bold Condensed'],
];

//  turn the substitutions into real fonts
var subsRight = [];
var fontCount = textFonts.length;
var subsCount = substitutions.length;
for (var i = 0; i < fontCount; i++) {
  var font = textFonts[i];
  for (var j = 0; j < subsCount; j++) {
    if (substitutions[j][2] == font.family && substitutions[j][3] == font.style) {
      subsRight[j] = font;
    }
  }
}

function getAllFiles(folder) {
  var fileList = [];
  function recurse (folder) {
    var files = folder.getFiles("*.ai");
    for (var i = 0; i < files.length; i++)
      fileList.push(files[i]);

    var folders = folder.getFiles();
    var len = folders.length;
    for (var i = 0; i < len; i++) {
      if (folders[i] instanceof Folder) {
        recurse(folders[i]);
      }
    }
  }
  if (folder != null && folder instanceof Folder)
    recurse(folder);
  return fileList;
}

var sourceFolder = Folder.myDocuments.selectDlg( 'Select the folder with Illustrator files in which you want to replace fonts');
var files = getAllFiles(sourceFolder);

for ( var i = 0; i < files.length; i++ ) {
  var file = files[i];
  var doc = app.open(file);

  // replace the font
  var frames = doc.textFrames;
  for ( var j = 0; j < frames.length; j++ ) {
    var ranges = frames[j].textRanges;
    for ( var k = 0; k < ranges.length; k++ ) {
      var range = ranges[k];
      for (var f = 0; f < subsCount; f++) {
        if (range.characterAttributes.textFont.family == substitutions[f][0] 
          && range.characterAttributes.textFont.style == substitutions[f][1]) {
          range.characterAttributes.textFont = subsRight[f];
        }
      }
    }
  }
  redraw();

  doc.save();
  doc.close();  
}

 

TOPICS
How to, Import and export, Scripting

Views

70

Likes

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
Jul 22, 2020 0
Adobe Community Professional ,
Jul 23, 2020

Copy link to clipboard

Copied

Hi,

To save ai document into EPS format you need to use saveAs method with EPSSaveOptions

Here is the complete updated version of the script with EPS format

var substitutions = [
  ['BellGothic BT', 'Bold', 'Roboto', 'Condensed'],
  ['BellGothic Blk BT', 'Black', 'Roboto', 'Bold Condensed'],
];

//  turn the substitutions into real fonts
var subsRight = [];
var fontCount = textFonts.length;
var subsCount = substitutions.length;
for (var i = 0; i < fontCount; i++) {
  var font = textFonts[i];
  for (var j = 0; j < subsCount; j++) {
    if (substitutions[j][2] == font.family && substitutions[j][3] == font.style) {
      subsRight[j] = font;
    }
  }
}

function getAllFiles(folder) {
  var fileList = [];
  function recurse(folder) {
    var files = folder.getFiles("*.ai");
    for (var i = 0; i < files.length; i++)
      fileList.push(files[i]);

    var folders = folder.getFiles();
    var len = folders.length;
    for (var i = 0; i < len; i++) {
      if (folders[i] instanceof Folder) {
        recurse(folders[i]);
      }
    }
  }
  if (folder != null && folder instanceof Folder)
    recurse(folder);
  return fileList;
}

var sourceFolder = Folder.myDocuments.selectDlg('Select the folder with Illustrator files in which you want to replace fonts');
var files = getAllFiles(sourceFolder);
var saveOptions = new EPSSaveOptions();
saveOptions.cmykPostScript = true;
saveOptions.embedAllFonts = true;

for (var i = 0; i < files.length; i++) {
  var file = files[i];
  var doc = app.open(file);

  // replace the font
  var frames = doc.textFrames;
  for (var j = 0; j < frames.length; j++) {
    var ranges = frames[j].textRanges;
    for (var k = 0; k < ranges.length; k++) {
      var range = ranges[k];
      for (var f = 0; f < subsCount; f++) {
        if (range.characterAttributes.textFont.family == substitutions[f][0]
          && range.characterAttributes.textFont.style == substitutions[f][1]) {
          range.characterAttributes.textFont = subsRight[f];
        }
      }
    }
  }
  redraw();
  var newFile = new File(file);
  doc.saveAs(newFile, saveOptions)

  //doc.save(); //Uncomment if you want to save changes you made in ai as well.
  doc.close();
}

Let us know if this helps you.

 

 

Best regards

Likes

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
Reply
Loading...
Jul 23, 2020 1
Community Beginner ,
Jul 23, 2020

Copy link to clipboard

Copied

Thank you.
However, this error is raised.

 

Error 2: saveOpions is undefined.
doc.saveAs(newFile, saveOpions)

 

I want to change the font by scripting the eps file.

But when I apply the script, it is created as an AI file.

I want to save it as it is in the original EPS file.

 

Help.
Thank you.

Likes

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
Reply
Loading...
Jul 23, 2020 0
Adobe Community Professional ,
Jul 24, 2020

Copy link to clipboard

Copied

Hi, There is a typo error in your spelling saveOpions. In my code it is saveOptions

saveOptions

Try this and let us know how it goes from here.

 

 

Best regards

Likes

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
Reply
Loading...
Jul 24, 2020 0
Community Beginner ,
Jul 24, 2020

Copy link to clipboard

Copied

Spelling made a mistake while typing in the warning window.

But when I run the script you modified
The folder selection window appears.
If you select a folder, nothing happens.
Thank you.

Likes

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
Reply
Loading...
Jul 24, 2020 0
Resources