6 Replies Latest reply on Apr 16, 2014 2:46 AM by Gejaraja

    How to access the contents applied with 'conditional text'?

    Gejaraja Level 1

      Hello All,

       

      I'd like to access the contents applied with 'conditional text' say 'english' without switching ON using JS, please advise.

       

      Thanks,

       

      Praveen

        • 1. Re: How to access the contents applied with 'conditional text'?
          Peter Spier Most Valuable Participant (Moderator)

          Moved to the scripting forum...

           

          You should ask scripting questions here in the future, please.

          • 2. Re: How to access the contents applied with 'conditional text'?
            Jump_Over Level 5

            Gejaraja wrote:

             

            ...without switching ON...

             

            Do you mean without switching its property "visible" ON?

            No way, I am afraid. If conditional text visibility is switched OFF - whole text disappears as an object, so story.length is changed and findText() returns null as well.

             

            Jarek

            • 3. Re: How to access the contents applied with 'conditional text'?
              Dave Saunders Level 4

              In attempting to provide a helpful response, I have myself run into an issue. I constructed a very simple example with the following text (Using InDesign CC 9.2.1.101):

               

              Hello Bonjour This is a message.

               

              I created (using the UI) two conditions named English and French. I applied English to "Hello " and French to "Bonjour ". I then set English invisible and selected the word "Bonjour " (including the trailing space. Now, using ESTK JavaScript Console I tried:

               

              app.selection[0].appliedConditions[0].name

               

              it returned:

               

              Error: undefined is not an object

               

              But if I try:

               

              app.selection[0].parentStory.textStyleRanges[1].appliedConditions[0].name

               

              it returns:

               

              Result: French

               

              Apparently, app.selection[0].parentStory.textStyleRanges[0] is the hidden English text.

               

              So, this is a puzzle.

               

              --------------------------

               

              And before I could post this, I realized what was happening: the selection includes the hidden English text. Wow, that's something to watch out for when working with conditions. If the selection you make in text is hard up against a hidden condition, that hidden text is incorporated into the selection yet it doesn't actually exist. But this doesn't affect non-condition related properties. For example pointSize returns the correct value.

               

              app.selection[0].insertionPoints[0].appliedConditions[0].name fails. As does app.selection[0].characters[0].appliedConditions[0].name. But app.selection[0].characters[1].appliedConditions[0].name correctly returns French.

               

              And now the real reason becomes clear: the first character is some kind of marker that invisibly indicates that there is hidden text at that location. But it appears to be a marker for which you cannot search.

               

              Hmm. I'm not sure whether I'm helping here!

               

              My original thought was that to address the question a script could note the state of the condition of interest, turn it on, analyze the affected text and then if necessary turn it off again.

               

              Dave

              • 4. Re: How to access the contents applied with 'conditional text'?
                Jump_Over Level 5

                Hi,

                @ Dave, could you check in your example:

                app.selection[0].parentStory.textStyleRanges.length;

                a) when both condition are visible

                b) when one is hidden

                 

                it looks differ on my side, so... no object... no puzzle...

                 

                Jarek

                • 5. Re: How to access the contents applied with 'conditional text'?
                  Dave Saunders Level 4

                  Everything works just fine when all is visible. The issue is that when text is invisible it is replaced by a marker that counts as a character as far as JS is concerned and which is selected if in the UI you click after the space and then do Command-Shift-Up-Arrow to select to the start of the paragraph (which I now realize is what I did).

                   

                  Dave

                  • 6. Re: How to access the contents applied with 'conditional text'?
                    Gejaraja Level 1

                    Hello Dave,

                     

                    Thanks for the details, now I able to get the condition details for the selected contents, but my requirement is to get the text applied with the conditions which will be available in hidden mode.

                     

                    Please advise.

                     

                    Thanks,

                     

                    Praveen