6 Replies Latest reply on Oct 27, 2016 10:59 AM by Laubender

    Move Table with appliedCondition

    Bubunator

      Hello,

       

      I have a Textframe  with several applied Conditions within. By looping through the condititions and doing a findGrep() for each of them, I can move the Text to a new Textframe. This already works out pretty good, if it wasnt for those tables within the conditional formatted Text.

       

      This is how my Script is working ( simplified ):

       

      app.findGrepPreferences.appliedConditions = currCondition; // currCondition is 1 of my Documents appliedConditions

      parts = app.activeDocument.findGrep();

       

      if(parts.length > 0){

      for (var i=0; i<parts.length; i++){

      if(  parts[i].contents.length > 0 ){

        parts[i].move(LocationOptions.AT_BEGINNING, newPage.textFrames[0]);  // newPage is an empty page, except for the 1 textFrame

        }

      }

      }

       

      When i select the table manually like this:

      u can see that the condition EPLUS_Inhalt is applied to it, or atleast to the paragraph(?) around the element. Hiding the condition DOES hide the table, but it wont be moved...

       

      Can anyone point me to the right direction, or atleast explain to me why my way is obviously the wrong way?

        • 1. Re: Move Table with appliedCondition
          Trevorׅ Adobe Community Professional

          Hi

           

          Greps can't find tables :-(

          You can only find them i.e. their selectors with findText

          app.findTextPreferences = null; 

          app.findTextPreferences.findWhat = "\x16"; 

          var tables = doc.findText(false);

           

          HTH

           

          Trevor

          • 2. Re: Move Table with appliedCondition
            Bubunator Level 1

            Hi,

             

            well it helps a bit, as i don't need try to find them via grep anymore

             

            But serious:

            I can grab the tables I need with this method, with the correct Condition and stuff. But i can't get a connection between the tables I found with findText() and the Text I grab with my Grep.

            When I have, lets say 3 paragraphs, with a table within, having a certain apllied Condition, I need the table to be at the exact same position after the moving as before.

             

            Right now, I could extract the text, move it into my new textframe, then extract the table and append it. Maybe I could insert the Table at the same insertionPoint after I moved my Text, but i cant even figure out the insertion point before moving it, because the parent of my found table ( tables[i] ) is the story itself, not the textFrame it's living in ( what I dont understand either).

             

            Is there even a way to do what I need to do?

            • 3. Re: Move Table with appliedCondition
              Trevorׅ Adobe Community Professional

              I'm not going to be available for the next few days but just as a leaving thought it might be easiest if not quickest to do the following

               

              1) loop through or everyItem() the textStyleRanges

              2) Index - put each range into an array according to it's condition

              3) move all the items in each indexed array.

               

              Pros

              Simple to code and will work :-)

               

              Con

              Might be a bit slow for the long docs :-(

               

              HTH

               

              Trevor

              • 4. Re: Move Table with appliedCondition
                Trevorׅ Adobe Community Professional

                Did you get this sorted out?

                • 5. Re: Move Table with appliedCondition
                  Obi-wan Kenobi Adobe Community Professional

                  Hi Trevor,

                   

                  Interested but surely not able to finish! Can you help?

                   

                  (^/) 

                  • 6. Re: Move Table with appliedCondition
                    Laubender Adobe Community Professional & MVP

                    Hi Obi-wan,

                    as Trevor already said:

                     

                    You have to find tables with the Text Find method.

                    Search for the applied condition plus the string for the special character that represents the table: <0016>

                    In the UI this is working:

                     

                    1-TableWithCondition-TextFind-Replace-with-UI.png

                     

                    By ExtendScript this would work like that:

                     

                    app.findTextPreferences = app.changeTextPreferences = null;
                    
                    app.findTextPreferences.appliedConditions = ["Condition-1"];
                    app.findTextPreferences.findWhat = "<0016>";
                    var foundTableCharacters = app.documents[0].findText();
                    
                    
                    for(var n=0;n<foundTableCharacters.length;n++)
                    {
                        $.writeln(foundTableCharacters[n].tables[0].columns.length);
                    }
                    

                     

                    Regards,

                    Uwe