任何想法为什么有时当调用脚本运行时它会启动 ExtendScript Toolkit 并停止?我认为这可能是当有很多文本要通过时。不确定每次都是这样。见下图脚本。
如果它停止它就停止在行: var new_string = this_text_frame.contents.replace(search_string, replace_string);
// Version 3
function myReplace(search_string, replace_string) {
var active_doc = app.activeDocument;
var text_frames = active_doc.textFrames;
if (text_frames.length > 0)
{
for (var i = 0 ; i < text_frames.length; i++)
{
var this_text_frame = text_frames[i];
var new_string = this_text_frame.contents.replace(search_string, replace_string);
if (new_string != this_text_frame.contents)
{
this_text_frame.contents = new_string;
}
}
}
}
myReplace(/^PRG.*/i, "");
myReplace(/.*EBOM.*/i, "");
myReplace(/^PH.*0000.*/i, "");
myReplace(/^PH.*00\/.*/i, "");
// N or W & 6 #'s & -S_ EX. N123456-S_ REPLACE with: N123456-S??? (THIS NEEDS TO BE ABOVE _ REPLACED BY SPACE)
myReplace(/([NW]\d{6}-S)_/i, "$1??? ");
myReplace(/_/gi, " ");
// 6 #'s & - or no - & 7 #'s & 1 to 3 #'s & - EX: 123456-1234567/123- REPLACE with: -123456-
myReplace(/(\d{6})-?\d{7}\/\d\d?\d?-/i, "-$1-");
myReplace(/(\d{6})-?\d{7}-\/\d\d?\d?-/i, "-$1-");
myReplace(/([NW]\d{6}-S)-INS-\d\d\/\d\d?-/i, "$1??? ");
myReplace(/-INS-\d\d\/\d\d?-/i, "* ");
// - That is only followed by one more - & Not having PIA & - & 2 to 3 #'s & / & 1 to 3 #'s & - EX: -7NPSJ_RH-001/9- REPLACE with * & Space
myReplace(/-[^-]*-\d\d\d?\/\d\d?\d?-/i, "* ");
myReplace(/ ?ASSEMBLY/gi, " ASY");
myReplace(/ ASS?Y+$| ASS?Y - | ASS?Y -| ASS?Y | ASS?Y- | ASS?Y-/gi, " ASY - ");
myReplace(/(MCA-|DS-?C1-?)/i, "-");
myReplace(/^DS-|^DI-|^PH-|MCA|^PAF-|^PAF|^FDR-|^FDR/i, "");
myReplace(/VIEW ([a-z])/i, "TTEMPP $1");
myReplace(/ ?\(?V?I?EW\)| ?\(?VIE[W)]?|^W\)| ?\(VI+$|^ ?\(VI| ?\(V+$|^ ?\(V| ?\(+$|^ ?\)/i, "");
myReplace(/TTEMPP ([a-z])/i, "VIEW $1");
myReplace(/([NW]\d{6}-S)-/i, "$1??? ");
myReplace(/([NW]\d{6}-S)\/.-/i, "$1??? ");
// Needs to be in this order
myReplace(/ AND /i, "&");
myReplace(/WASHER/i, "WSHR");
myReplace(/BOLT/i, "BLT");
myReplace(/STUD/i, "STU");
myReplace(/([SCREW|SC|NUT|BLT|STU])&WSHR/i, "$1 & WSHR");
myReplace(/\?\?\? SCREW &/i, "??? SC &");
myReplace(/\?\?\? SC [^&]/i, "??? SCREW ");
myReplace(/(\?\?\? SC & WSHR).*/i, "$1");
myReplace(/(\?\?\? SCREW).*/i, "$1");
myReplace(/(\?\?\? NUT & WSHR).*/i, "$1");
myReplace(/\?\?\? NUT [^&].*/i, "??? NUT");
myReplace(/(\?\?\? BLT & WSHR).*/i, "$1");
myReplace(/\?\?\? BLT [^&].*/i, "??? BLT");
myReplace(/(\?\?\? STU & WSHR).*/i, "$1");
myReplace(/\?\?\? STU [^&].*/i, "??? STU");
myReplace(/--/gi, "-");
if ( app.documents.length > 0 && app.activeDocument.textFrames.length > 0 ) {
// Set the value of the word to look for
searchWord1 = "*";
//searchWord2 = "The";
// Iterate through all words in the document
// the words that match searchWord
for ( i = 0; i < app.activeDocument.textFrames.length; i++ ) {
textArt = activeDocument.textFrames[i];
for ( j = 0; j < textArt.characters.length; j++) {
word = textArt.characters[j];
if ( word.contents == searchWord1 ) {
word.verticalScale = 120;
word.horizontalScale = 140;
word.baselineShift = -3;
}
}
}
}
[img]http://i.imgur.com/9IRy9.jpg[/img]
调用此 javascript 以从 applescript 运行。
set Apps_Folder to (path to applications folder as text)
set Scripts_Path to "Adobe Illustrator CS5:Presets.localized:en_US:Scripts:"
set JS_FileName to "Text Find & Replace.jsx"
--
try
set JS_File to Apps_Folder & Scripts_Path & JS_FileName as alias
tell application "Adobe Illustrator"
do javascript JS_File show debugger on runtime error
end tell
on error
display dialog "Script file '" & JS_FileName & "' NOT found?" giving up after 2
end try