5 Replies Latest reply on Jun 12, 2017 9:56 AM by Ananth@desgin

    Change Internal References

    Ananth@desgin Level 2

      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[i].changeGrep();
      
          mChange+=re.length;
      
      }
      
      app.findGrepPreferences = app.changeGrepPreferences = null;
      
      alert("find:"+mFind.length+",change:"+mChange);
      }