4 Replies Latest reply on Sep 27, 2010 1:20 AM by Marcos Suárez

    CROSS REFERENCE SCRIPT BETWEEN TWO POINTS MARKED...

    Marcos Suárez

      I need to do a cross reference between two points in the document marked #1a and #1b: where is the #1a must appear the page number of the location of #1b... And where is #1b must appear the page number of the location of #1a ...

      Can this be done with a script in CS4...?

       

      Thanks.

        • 1. Re: CROSS REFERENCE SCRIPT BETWEEN TWO POINTS MARKED...
          Kasyan Servetsky Level 5

          Yes, here is a sample script to get you started. It's a very basic version -- the final version is quite different and works much faster (I can't post its code because of commercial agreement). You can find demo version and description here.

           

          Kasyan

          1 person found this helpful
          • 4. Re: CROSS REFERENCE SCRIPT BETWEEN TWO POINTS MARKED...
            Marcos Suárez Level 1
            I modified the script to get what I wanted ...
            Here it is if someone is interested ...
            The tags should be:
            #1o#.......................#1d#
            #2o#.......................#2d#
            #3o#.......................#3d#
            ........

             

            var myDoc = app.activeDocument;
            //*************************************************************************************************************
            //********************************************* BACK REFERENCES ****************************************
            app.findGrepPreferences = NothingEnum.nothing;
            app.changeGrepPreferences = NothingEnum.nothing;
            app.findChangeGrepOptions.includeFootnotes = false;
            app.findChangeGrepOptions.includeHiddenLayers = false;
            app.findChangeGrepOptions.includeLockedLayersForFind = false;
            app.findChangeGrepOptions.includeLockedStoriesForFind = false;
            app.findChangeGrepOptions.includeMasterPages = false;
            //***********
            app.findGrepPreferences.findWhat = "(#)(o)(\\d+)#";
            //***********
            app.changeGrepPreferences.changeTo = "$1$2$3$1$1f$39$1";
            myDoc.changeGrep();
            //***********
            app.findGrepPreferences = NothingEnum.nothing;
            app.changeGrepPreferences = NothingEnum.nothing;
            //***********
            app.findGrepPreferences.findWhat = "(#)(d)(\\d+)#";
            //***********
            app.changeGrepPreferences.changeTo = "$1$2$3$1$1i$39$1";
            myDoc.changeGrep();
            //***********
            app.findGrepPreferences = NothingEnum.nothing;
            app.changeGrepPreferences = NothingEnum.nothing;
            //*************************************************************************************************************
            //*********************************************** SCRIPT  ****************************************************
            var myHighligh, myBorderColor, myWidth, myBorderStyle;
            var myCrossRefFormats = myDoc.crossReferenceFormats.everyItem().name;
            var myTypeList = ["Visible Rectangle", "Invisible Rectangle"];
            var myHighlightList = ["None", "Invert", "Outline", "Inset"];
            var myHighlightEnumList = ["NONE", "INVERT", "OUTLINE", "INVERT"];
            var myBorderColDesList = ["Black", "Blue", "Brick red", "Brown", "Burgundy"];
            var myBorderColEnumList = ["BLACK", "BLUE", "BRICK_RED", "BROWN", "BURGUNDY"];
            var myWidthList = ["Thin", "Medium", "Thick"];
            var myWidthEnumList = ["THIN", "MEDIUM", "THICK"];
            var myStyleList = ["Solid", "Dashed"];
            var myStyleEnumList = ["SOLID", "DASHED"];
            var mySet = GetSettings();
            CreateDialog();
            //-------------------------------------- FUNCITIONS ---------------------------------------------
            function Main() {
             myHighligh = eval("HyperlinkAppearanceHighlight." + myHighlightEnumList[mySet.myDdl3Sel]);
             myBorderColor = eval("UIColors." + myBorderColEnumList[mySet.myDdl4Sel]);
             myWidth = eval("HyperlinkAppearanceWidth." + myWidthEnumList[mySet.myDdl5Sel]);
             myBorderStyle = eval("HyperlinkAppearanceStyle." + myStyleEnumList[mySet.myDdl6Sel]);
             CreateDestinations();
             CreateHyperlinks();
             CreateDestinations2();
             CreateHyperlinks2();
             alert("Done.");
            }  
              
            function CreateDialog() {
             var myDialog = new Window("dialog", "Create Cross-Reference Settings");
             myDialog.orientation = "column";
             myDialog.alignChildren = "fill";
             
             var myXrefPanel = myDialog.add("panel", undefined, "Cross-Reference Format");
             myXrefPanel.orientation = "column";
             myXrefPanel.alignChildren = "right";
             
             var myGroup1 = myXrefPanel.add("group");
             myGroup1.orientation = "row";
             var myStTxt1 = myGroup1.add("statictext", undefined, "Format:");
             var myDropDownList1 = myGroup1.add("dropdownlist", undefined, myCrossRefFormats);
             myDropDownList1.selection = mySet.myDdl1Sel;
             
             var myPanel = myDialog.add("panel", undefined, "Appearance");
             myPanel.orientation = "row";
             
             var myLeftGroup = myPanel.add("group");
             myLeftGroup.orientation = "column";
             myLeftGroup.alignChildren = "right";
             
             var myRightGroup = myPanel.add("group");
             myRightGroup.orientation = "column";
             myRightGroup.alignChildren = "right";
              
             var myGroup2 = myLeftGroup.add("group");
             myGroup2.orientation = "row";
             var myStTxt2 = myGroup2.add("statictext", undefined, "Type:");
             myStTxt2.justify = "right";
             var myDropDownList2 = myGroup2.add("dropdownlist", undefined, myTypeList);
             myDropDownList2.selection = mySet.myDdl2Sel;
             myDropDownList2.onChange = TypeOnChange;
             var myGroup3 = myLeftGroup.add("group");
             myGroup3.orientation = "row";
             var myStTxt3 = myGroup3.add("statictext", undefined, "Highlight:");
             myStTxt3.justify = "right";
             var myDropDownList3 = myGroup3.add("dropdownlist", undefined, myHighlightList);
             myDropDownList3.selection = mySet.myDdl3Sel;
             
             var myGroup4 = myLeftGroup.add("group");
             myGroup4.orientation = "row";
             var myStTxt4 = myGroup4.add("statictext", undefined, "Colour:");
             myStTxt4.justify = "right";
             var myDropDownList4 = myGroup4.add("dropdownlist", undefined, myBorderColDesList);
             myDropDownList4.selection = mySet.myDdl4Sel;
             var myGroup5 = myRightGroup.add("group");
             myGroup5.orientation = "row";
             var myStTxt5 = myGroup5.add("statictext", undefined, "Width:");
             myStTxt5.justify = "right";
             var myDropDownList5 = myGroup5.add("dropdownlist", undefined, myWidthList);
             myDropDownList5.selection = mySet.myDdl5Sel;
             
             var myGroup6 = myRightGroup.add("group");
             myGroup6.orientation = "row";
             var myStTxt6 = myGroup6.add("statictext", undefined, "Style:");
             myStTxt6.justify = "right";
             var myDropDownList6 = myGroup6.add("dropdownlist", undefined, myStyleList);
             myDropDownList6.selection = mySet.myDdl6Sel;
             
             var myOkCancelGroup = myDialog.add("group");
             myOkCancelGroup.orientation = "row";
             myOkCancelGroup.alignment = "center";
             var myOkBtn = myOkCancelGroup.add("button", undefined, "Ok", {name:"ok"});
             var myCancelBtn = myOkCancelGroup.add("button", undefined, "Cancel", {name:"cancel"});
             
             if (mySet.myDdl2Sel == 1) {
              myDropDownList4.enabled = false;
              myDropDownList5.enabled = false;
              myDropDownList6.enabled = false;
              myStTxt4.enabled = false;
              myStTxt5.enabled = false;
              myStTxt6.enabled = false;
             }
             
             function TypeOnChange() {
              if (this.selection.index == 0) {
               myDropDownList4.enabled = true;
               myDropDownList5.enabled = true;
               myDropDownList6.enabled = true;
               myStTxt4.enabled = true;
               myStTxt5.enabled = true;
               myStTxt6.enabled = true;
              }
              else if (this.selection.index == 1) {
               myDropDownList4.enabled = false;
               myDropDownList5.enabled = false;
               myDropDownList6.enabled = false;
               myStTxt4.enabled = false;
               myStTxt5.enabled = false;
               myStTxt6.enabled = false;
              }
             }
             
             var myShowDialog = myDialog.show();
             
             if (myShowDialog== 1) {
              mySet.myDdl1Sel = myDropDownList1.selection.index;
              mySet.myDdl2Sel = myDropDownList2.selection.index;
              mySet.myDdl3Sel = myDropDownList3.selection.index;
              mySet.myDdl4Sel = myDropDownList4.selection.index;  
              mySet.myDdl5Sel = myDropDownList5.selection.index;
              mySet.myDdl6Sel = myDropDownList6.selection.index;  
              app.insertLabel("Kas_CreateCrossReferences_1", mySet.toSource());
              Main();
             }
            }
            //--------------------------------------------------------------------------------------------------------------
            function GetSettings() {
             var mySettings = eval(app.extractLabel("Kas_CreateCrossReferences_1"));
             if (mySettings == undefined) {
              mySettings = { myDdl1Sel:8,  myDdl2Sel:0, myDdl3Sel:0, myDdl4Sel:0, myDdl5Sel:0, myDdl6Sel:0}
             }
             return mySettings;
            }
            //--------------------------------------------------------------------------------------------------------------
            function CreateDestinations() {
             app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
             app.findGrepPreferences.findWhat = "#d\\d+#";
             var myFinds = myDoc.findGrep(); 
             for ( var j = myFinds.length-1; j >= 0; j-- ) {
              var myFound = myFinds[j];
              var myHypTextDest = myDoc.hyperlinkTextDestinations.add(myFound);
              myHypTextDest.name = myFound.contents.match(/\d+/)[0];
              myFound.contents = "";
             }
            }
            //--------------------------------------------------------------------------------------------------------------
            function CreateHyperlinks() {
             var xRefFormat = myDoc.crossReferenceFormats.item(mySet.myDdl1Sel); 
             app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
             app.findGrepPreferences.findWhat = "#o\\d+#";
             var myFinds = myDoc.findGrep();
             for ( var j = myFinds.length-1; j >= 0; j-- ) {
              var myFound = myFinds[j];
              var mySourceText = myFound;
              var mySourceName = myFound.contents.match(/\d+/)[0];
              var mySource = myDoc.crossReferenceSources.add(mySourceText, xRefFormat);
              mySource.name = mySourceName;
              
              var myHypDest = myDoc.hyperlinkTextDestinations.itemByName(mySourceName);
              if (myHypDest.isValid) {
               var myHyperLink = myDoc.hyperlinks.add(mySource, myHypDest);
               myHyperLink.visible = (mySet.myDdl2Sel == 1) ? false : true;
               myHyperLink.highlight = myHighligh;
               myHyperLink.borderColor = myBorderColor;
               myHyperLink.width = myWidth;
               myHyperLink.borderStyle = myBorderStyle;
               
               try{
                myHyperLink.name = mySourceName;
               }
               catch(e) {
                $.writeln(j + " - Error: " + e);
               }
              }
              else {
               $.writeln(j + " - " + myHypDest.name + " is Not Valid");
              }
             }
            }
            //*********************************************************** NEW FUNCTIONS*********************************************************************
            //*****************************************************************************************************************************************************
            function CreateDestinations2() {
             app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
             app.findGrepPreferences.findWhat = "#f\\d+#";
             var myFinds = myDoc.findGrep(); 
             for ( var j = myFinds.length-1; j >= 0; j-- ) {
              var myFound = myFinds[j];
              var myHypTextDest = myDoc.hyperlinkTextDestinations.add(myFound);
              myHypTextDest.name = myFound.contents.match(/\d+/)[0];
              myFound.contents = "";
             }
            }
            //--------------------------------------------------------------------------------------------------------------
            function CreateHyperlinks2() {
             var xRefFormat = myDoc.crossReferenceFormats.item(mySet.myDdl1Sel); 
             app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
             app.findGrepPreferences.findWhat = "#i\\d+#";
             var myFinds = myDoc.findGrep();
             for ( var j = myFinds.length-1; j >= 0; j-- ) {
              var myFound = myFinds[j];
              var mySourceText = myFound;
              var mySourceName = myFound.contents.match(/\d+/)[0];
              var mySource = myDoc.crossReferenceSources.add(mySourceText, xRefFormat);
              mySource.name = mySourceName;
              
              var myHypDest = myDoc.hyperlinkTextDestinations.itemByName(mySourceName);
              if (myHypDest.isValid) {
               var myHyperLink = myDoc.hyperlinks.add(mySource, myHypDest);
               myHyperLink.visible = (mySet.myDdl2Sel == 1) ? false : true;
               myHyperLink.highlight = myHighligh;
               myHyperLink.borderColor = myBorderColor;
               myHyperLink.width = myWidth;
               myHyperLink.borderStyle = myBorderStyle;
               
               try{
                myHyperLink.name = mySourceName;
               }
               catch(e) {
                $.writeln(j + " - Error: " + e);
               }
              }
              else {
               $.writeln(j + " - " + myHypDest.name + " is Not Valid");
              }
             }
            }