Article View: adobe.incopy.scripting
Article #80INCOPY SCRIPT -- What's wrong with this script??
From: veronica_olvera
Date: Fri, 03 Apr 2009 21:24
Date: Fri, 03 Apr 2009 21:24
107 lines
4640 bytes
4640 bytes
Could someone please tell me what's wrong with the below script? I need it to use the FindChangeList to do some basic formatting (replacing double-dashes with em-dashes), then apply the next style, then find my last two lines and format them to a paragraph style, THEN map styles to tags. It's all working EXCEPT it does not do the initial "find/replace" formatting. I suspect it's a conflict of the FindChangeList somehow?? Any and all help is appreciated.
//FindChangeByList.jsx
main();
function main(){
var myObject;
var myCheckSelection = false;
if(app.documents.length > 0){
if(app.selection.length > 0){
switch(app.selection[0].constructor.name){
case "InsertionPoint":
case "Character":
case "Word":
case "TextStyleRange":
case "Line":
case "Paragraph":
case "TextColumn":
case "Text":
myObject = myDisplayDialog();
myCheckSelection = myObject[1];
myObject = myObject[0];
if(myObject != "None"){
myFindChangeByList(myObject, myCheckSelection);
}
break;
default:
myFindChangeByList(app.documents.item(0), false);
}
}
else{
//Nothing was selected, so simply search the document.
myFindChangeByList(app.documents.item(0), false);
}
}
else{
alert("No documents are open. Please open a document and try again.");
}
}
function myDisplayDialog(){
var myObject;
var myDialog = app.dialogs.add({name:"FindChangeByList"});
with(myDialog.dialogColumns.add()){
with(dialogRows.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Search Range:"});
}
var myRangeButtons = radiobuttonGroups.add();
with(myRangeButtons){
radiobuttonControls.add({staticLabel:"Selection"});
radiobuttonControls.add({staticLabel:"Selected Story"});
radiobuttonControls.add({staticLabel:"Document", checkedState:true});
}
}
}
var myResult = myDialog.show();
if(myResult == true){
switch(myRangeButtons.selectedButton){
case 0:
myObject = app.selection[0];
myCheckSelection = true;
break;
case 1:
myObject = app.selection[0].parentStory;
myCheckSelection = false;
break;
case 2:
myObject = app.documents.item(0);
myCheckSelection = false;
break;
}
}
else{
myObject = "None";
}
myDialog.destroy();
return [myObject, myCheckSelection];
}
function myFindChangeByList(myObject, myCheckSelection){
var myScriptFileName, myFindChangeFile, myFindChangeFileName, myScriptFile, myResult;
var myFindChangeArray, myFindPreferences, myChangePreferences, myFindLimit;
var myStartCharacter, myEndCharacter;
var myFindChangeFile = myFindFile("/FindChangeSupport/FindChangeList.txt")
if(myFindChangeFile != null){
// Because the selection will change as we add/remove characters,
// we'll need to reset the selection after each pass if we are
// checking the selection. We'll get the index of the first character
// in the selection (relative to the start of its parent story) and
// the index of the last character in the selection (relative to the
// *end* of the story, and we'll use them later in the script to
// keep the ends of the selection in place.
if(myCheckSelection == true){
var myStart = myObject.characters.item(0).index;
var myEnd = myObject.characters.item(-1).index;
var myStory = myObject.parentStory;
var myStoryEnd = myStory.characters.item(-1).index;
myEnd = (myStoryEnd - myEnd)+1;
}
myFindChangeFile = File(myFindChangeFile);
var myResult = myFindChangeFile.open("r", undefined, undefined);
if(myResult == true){
//Loop through the find/change operations.
do{
myLine = myFindChangeFile.readln();
//Ignore comment lines and blank lines.
if((myLine.substring(0,4)!="text")||(myLine.substring(0,4)!="grep")||(myLine.substring(0,5)!="glyph")){
myFindChangeArray = myLine.split("\t");
//
Technical Details
Message-ID:
<59b8814b.-1@webcrossing.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!newshub.sdsu.edu!webcrossingShow Full Headers
Complete Article Headers
X-Google-Thread: 1efe4a,38a20274dcd741f4,start X-Google-Attributes: gid1efe4a,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: veronica_olvera@adobeforums.com Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!newshub.sdsu.edu!webcrossing Newsgroups: adobe.incopy.scripting Subject: INCOPY SCRIPT -- What's wrong with this script?? Message-ID: <59b8814b.-1@webcrossing.la2eafNXanI> Date: Fri, 3 Apr 2009 14:24:57 -0700 Lines: 124 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit