Copy link to clipboard
Copied
Hi All,
I have work with custom books. I want to change custom books chapter numbers and update the internal references such as figure, table, Map, Lab.
Example i take chapter 5 to change the chapter 1 and internal references
Before After
Figure 5.1 Figure 1.1
Figure 5.2 Figure 1.2
..... ............
Figure 5.15 Figure 1.15
how can i do this...?
var myDoc = app.activeDocument;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "[A-z]+"
var Found = app.activeDocument.findGrep();
for(i=0; i<Found.length; i++)
{
if((Found.contents = "FIGURE")&&(Found.contents = "Figure")&&(Found.contents = "figure")&&(Found.contents = "Fig")&&(Found.contents = "fig"))
{
//Found.fillColor = "Red";
}
}
Copy link to clipboard
Copied
Hi Ananth,
You'd probably be better off making a GREP for each change you want to make.
At the moment your if statement will only be true if the content of the GREP matches all of your strings.
If you want to match any of them, use the or operator, like so:
if((Found.contents = "FIGURE")||(Found.contents = "Figure")||(Found.contents = "figure")||(Found.contents = "Fig")||(Found.contents = "fig"))
Jake
Copy link to clipboard
Copied
Just a quick go at a possible GREP expression:
([Ff]ig(ure)?)
That will find all of the strings in your example, except for the all caps version.
Copy link to clipboard
Copied
thanks for your reply jack!!!
thanks,
prabu
Copy link to clipboard
Copied
Hi
i have to work user Interface and give the input:
old chapter: 1
New chapter: 5
it will be change the internal reference and change the year(Ex: 1955 inside the para) and number list. how to presreve this?
if(app.documents.length == 0)
{
alert("Hi User!! Please open the Document")
exit();
}
var myDoc = app.documents[0];
var window = new Window ("dialog", "Change Cross-References");
window.orientation = "row";
window.preferredSize.width = 100;
window.preferredSize.height = 100;
window.location = [500, 400];
window.add ("statictext", undefined, "Old_Chapter:");
var find_ref = window.add ("edittext", undefined, "");
window.graphics.backgroundColor = window.graphics.newBrush (window.graphics.BrushType.SOLID_COLOR, [0, 0.5, 0.5, 0.5]);
find_ref.characters = 30;
window.orientation = "column";
window.add ("statictext", undefined, "New_Chapter:");
var change_Ref = window.add ("edittext", undefined, "");
change_Ref.characters = 30;
var myButtonGroup = window.add ("group");
myButtonGroup.alignment = "right";
var Ok =myButtonGroup.add ("button", undefined, "OK");
var Cancel = myButtonGroup.add ("button", undefined, "Cancel");
var myResult = window.show();
//~ if(Cancel.onclick ==1)
//~ {
//~ alert("Hi User!! Please Enter the values")
//~ exit()
//~ }
var old_Ref = find_ref.text;
var new_Ref = change_Ref.text;
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.findWhat = old_Ref;
var found = app.documents[0].findText();
for(i=0; i<found.length; i++)
{
app.findChangeTextOptions.caseSensitive = false;
app.findChangeTextOptions.wholeWord = false;
app.changeTextPreferences.changeTo = new_Ref;
var myChanges = app.documents[0].changeText();
}
if(found.length==0)
{
alert("Hi User!! no text found")
exit()
}
app.findTextPreferences = app.changeTextPreferences = null;
thanks,
Prabu
Copy link to clipboard
Copied
If your chapter number have any paragraph style then use .appliedParagraphStyle in find preference