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
Now i am using below script it changes all figure internal references and also change the other chapter internal refernces.
Example:
Before After
Figure 5.1 Figure 1.1
Figure 5.2 Figure 1.2
..... ............
see Figure 15.1 Figure 11.1
if(app.documents.length == 0)
{
alert("Hi User!! Please open the Document")
exit();
}
var mywindow = new Window ("dialog", "Change Cross-References");
mywindow.orientation = "column";
mywindow.preferredSize.width = 100;
mywindow.preferredSize.height = 100;
mywindow.location = [500, 400];
mywindow.graphics.backgroundColor = mywindow.graphics.newBrush (mywindow.graphics.BrushType.SOLID_COLOR, [0, 0.5, 0.5, 0.5]);
var Selected_Chapters = mywindow.add ("statictext", undefined, "Enter Old chapters in numbers");
var Old_Chapters = mywindow.add ("edittext", undefined, "");
Old_Chapters.characters = 10;
Old_Chapters.active = true;
var New_Chapters = mywindow.add ("statictext", undefined, "Enter Change chapters in numbers");
var Change_Chapters= mywindow.add ("edittext", undefined, "");
Change_Chapters.characters = 10;
Change_Chapters.active = true;
var myOK_Button = mywindow.add ("button", undefined, "OK")
var myCancel_Button = mywindow.add ("button", undefined, "Cancel", {canCancel:true})
if (mywindow.show () == 1)
{
//step1
var myDoc = app.activeDocument, mFind,mChange=0;
var Old_Chapter = Old_Chapters.text; // Find chapter
var New_Chapter = Change_Chapters.text; // Change Chapter
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "figure\\s\\d+|Figure\\s\\d+|FIGURE\\s\\d+";
mFind=myDoc.findGrep();
//step2
for(var i=0;i<mFind.length;i++) {
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = Old_Chapter;
app.changeGrepPreferences.changeTo = New_Chapter;
var re=mFind.changeGrep();
mChange+=re.length;
}
app.findGrepPreferences = app.changeGrepPreferences = null;
alert("find:"+mFind.length+",change:"+mChange);
}
Copy link to clipboard
Copied
Hi,
Any suggestion please..
Thanks
Copy link to clipboard
Copied
You're looking for 'figure ' followed by any digit. You should look for 'figure ' followed by a specific digit (if I understand you correctly).
Copy link to clipboard
Copied
Hi pkaherl,
Thanks for your reply. Am looking figure followed by my input digit.
Example figure 5.1 change to figure 1.1.
Old chapter box my input is 5
New chapter box my input is 1
If click OK button it will be change to figure 1.1
Above code changed figure 5.1 to figure 1.1 and also See figure 15.1 changed figure 11.1
Thanks
Prabu
Copy link to clipboard
Copied
Again, you're matching 'figure ' followed by any number.
Why the loop, by the way? You can do this:
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "(?i)figure\\s\\K" + Old_Chapters.text;
app.findGrepPreferences.changeTo = New_Chapter.text;
mFind=myDoc.changeGrep();
(?i) means 'search case-insensitively
\K denotes a lookbehind
Copy link to clipboard
Copied
Hi,
Thanks for your help. I worked with your script it's changes,
Figure 5.1 to 1.1
figure 5.1 to 1.1
Figure 15.1 not changed
Thanks,
Prabu