5 Replies Latest reply on Nov 4, 2016 3:12 PM by Obi-wan Kenobi

    Select several tables …

    Obi-wan Kenobi Level 5

      Hi all,


      I've written a little script that works fine after "manually" selecting several tables using the text selection where they are placed.

      I would like to play inserting a find/replace to find (through a "condition" I use to mark the group, via text) marked tables groups I would want to be treated!


      What I don't actually know is how to write the code that'll allow me to select the paras chain! 


      My actual script:


      var myDoc = app.activeDocument;
      var mySel = app.selection[0];  
      var myCurTable = mySel.convertToTable("\r",",");   
            myCurTable.appliedTableStyle = "X_Table";           
            myCurTable.clearTableStyleOverrides( true );   


      I have this:


      Capture d’écran 2016-05-29 à 18.46.01.png


      I finally get this:


      Capture d’écran 2016-05-29 à 18.47.03.png


      To be clearer, I did this video:




      Thanks in advance! 

        • 1. Re: Select several tables …
          Obi-wan Kenobi Level 5



          I don't see how to catch together these "<0016>"! 



          • 2. Re: Select several tables …
            Laubender Adobe Community Professional & MVP

            Alright. Let's exaggerate a bit and do a search by Text with "<0016>" on your text selection.


            // Text is selected:
            var scopeOfInterest = app.selection[0];
            app.findTextPreferences = null;
            app.findTextPreferences.findWhat = "<0016>";
            var resultArray = scopeOfInterest.findText();
            if(resultArray.length >0)
                // to duplicate the first found table to a new text frame simply do:
                var newTextFrame = app.documents[0].layoutWindows[0].activeSpread.textFrames.add({geometricBounds : [0,0,100,100]});
                resultArray[0].duplicate(LocationOptions.AFTER , newTextFrame.insertionPoints[0] );
            // After that fit your text frame to contents, if the size of the table allows this.
            // And anchor the text frame to an insertion point right after your selection.



            • 3. Re: Select several tables …
              Obi-wan Kenobi Level 5



              Good beginning!


              My problem I don't try to fix is that I want to catch "following" tables not each table!


              So, never one isolated table in the text, but 2, 3 or more!

              The parameter is: I catch this table because it's followed by another or preceded by one!



              • 4. Re: Select several tables …
                Laubender Adobe Community Professional & MVP

                You could do a search based on individual lines of text or paragraphs and write the table characters found to an array to keep them managable together.
                You could also do a label on a table with a numbering/naming scheme, that you can follow later after moving the table.


                The table in the found character "<0016>" is:


                foundCharacter.tables[0].label = "My text string or numbering scheme";




                foundCharacter.tables[0].insertLabel("Key string" , "value string, that is a naming or numbering scheme");


                If you then do a text search based on e.g. "<0016>" or gather your tables by other means, you could filter out the tables you are interested in.


                if(foundCharacter.tables[0].extractLabel("Key string") == "My table of interest 103" )
                { doSomethingWithThatTable(foundCharacter.tables[0]) };


                Or a bit more flexible:


                if(foundCharacter.tables[0].extractLabel("Key string").match(/10\d$/) );
                { doSomethingWithThatTable(foundCharacter.tables[0]) };


                Note 1: Duplicating tables or copy/paste tables will also duplicate the applied labels.


                Note 2: .label = "String" is a special case of insertLabel() :

                .insertLabel("Label","Value"); is the same as .label = "String";

                Extracting a label value can be done like that:




                And as you already know, label values can be seen in the UI with the Script Label panel.

                Also labels with selected tables.



                • 5. Re: Select several tables …
                  Obi-wan Kenobi Level 5

                  Hi Uwe,


                  New learning about "Label" concept! 


                  See you soon about my future tries!


                  Thanks for all!