8 Replies Latest reply on Jul 31, 2015 5:37 AM by selvam214

    Find nested characters and apply the Cstyle

    selvam214 Level 1

      I

      want to find the nested applied characters and apply the Cstyle, but my code capture all those text in a document. Can you please guide to me,

       

      nestedreport();

      function nestedreport(){

      var myDoc = app.activeDocument;

      var myDocPath = myDoc.filePath;

      var myDocName = myDoc.name;

       

       

      try{

      app.findGrepPreferences = app.changeTextPreferences = null;

      app.findGrepPreferences.findWhat = "^.+";

      myFind=myDoc.findGrep(false);

       

      var ntexts = new Array;

      for(i=myFind.length-1;i>=0;i--)

      {

          if(myFind[i].contents.nestedStyles==null)

          {

              ntexts.push(myFind[i].contents)

              ntexts.appliedCharacterStyle="Nested";

              }

          }

      }

      catch(e){}

       

      }

       

       

      Screen shot 2015-07-21 at 2.26.33 PM.png

        • 1. Re: Find nested characters and apply the Cstyle
          Jump_Over Level 5

          Hi,

           

          2 problems (at least):

           

          1.

          ...

          to find the nested applied characters

          ...

          What are you exactly going to find?

          If some text is "nested applied" ==> cStyle supposes to be defined already...

          Is a dropCap an example of your "nested applied character"?

          It could be plenty of occurences of "nested" format made manually (color, font, size... every character property).


          You need to define how to detect if THIS character is your goal and THIS is not.

           

          2.

          ...

              if(myFind[i].contents.nestedStyles==null)

          ...

          Above is always true (always null).  Property "contents" returns a String ==> so there is no such string property like "nestedStyles" to check.

          Thats why your script is applying cStyle "Nested" to every paragraph found in myDoc

           

          Jarek

          • 2. Re: Find nested characters and apply the Cstyle
            Peter Kahrel Adobe Community Professional & MVP

            Selvam214 -- Like Jarek, I struggle to understand what you mean and how you go about it. What do you mean by 'nested applied characters'? And again, as Jarek mentioned, there are several problems with your code:

             

            1. ^.+ matches whole paragraphs, which explains why "my code capture all those text in a document". What you're after is probably the first character of each paragraph.

            2. appliedNestedStyle (not nestedStyles) is a property of text objects (a Paragraph object, Character object, etc.), not of strings (.contents).

            3. To test whether an object has a nested style applied, you do

            if (myFind[i].appliedNestedStyles.length === 0) {
              // No nested styles applied to myFind[i]
            }
            
            

            4. In your code, ntexts is an array of strings, and you can't apply a character style to arrays of strings (not to any array, in fact), so ntexts.appliedCharacterStyle="Nested"; doesn't work (probably throws an error, in fact).

             

            So, tell us what you want to achieve.

             

            Peter

            • 3. Re: Find nested characters and apply the Cstyle
              selvam214 Level 1

              Hi Jarek and Peter,

               

              This is our process.

               

              We have used more nested styles with different concepts. Finally, all those nested styles to apply proper character styles and export to the styled word (cstyle and pstyle).

               

               

               

               

              Example nested occurrences below:

               

              1. First line small caps with some italic words (italic is manual override)

              Screen shot 2015-07-21 at 5.35.47 PM.png

               

              2. Bold/small cap words with special character separator

               

              Screen shot 2015-07-21 at 5.31.17 PM.png

               

              Screen shot 2015-07-21 at 5.30.35 PM.png

               

               

              3. Font size increased first letter with Cstyle

              Screen shot 2015-07-21 at 2.26.33 PM.png

               

              4. Color words with separator

               

              Screen shot 2015-07-21 at 5.31.17 PM.png

               

              5. Multi character style used in single entry (nested)

              Screen shot 2015-07-21 at 5.32.19 PM.png

               

               

              We have used many option with different style (scripting), but some occurrences the code combination not workout and some occurrences the format also not support (manual overrides). So i have two small root of identification below, can you please suggest to the below methods are ok, or if any other way fix this issue.

               

              1. All nested style to apply one common cstyle (Nested)

              2. Opening and closing tags add to this content (<n>Clermont</n>)

               

              Kindly suggest.

               

              Thanks

              Selva

              • 4. Re: Find nested characters and apply the Cstyle
                Jump_Over Level 5

                Hi,

                 

                First at all - nested means dynamic. It is a kind of built-in utility used to format text but with relation to various condition.

                The same text (with the same nestedStyle applied) will be displayed differently depending on textFrame width, column's count, delimiter occurence, etc)

                 

                Are you going to tag "currently displayed" text and be able to reapply this format somewhere in external location?

                 

                Jarek

                • 5. Re: Find nested characters and apply the Cstyle
                  selvam214 Level 1

                  Hi Jarek,

                  Yes.

                  (I will choose this, may be we haven't the solution).

                   

                  Because, I have tried various method with different option. But, I can't get 100% result from the nested styles. Reason for  reflow, overrides and wrong type faces .... For example, I have mentioned in first screen shot (black background - previous thread), I tried to get the small caps text with italic content, but the result is 'the last word' goes to next line and converted to the roman (as per the nested rules fixed).  

                   

                  Please suggest.

                   

                  Selva

                  • 6. Re: Find nested characters and apply the Cstyle
                    Jump_Over Level 5

                    Hi,

                     

                    I am still struggled a little with the final goal, however lets do a small step:

                     

                    To detect a string which is formated using nestedStyle (part of paragraph's contents) you could use this:

                              assuming ==> some text is selected - lets say some paragraph

                     

                    var
                      cCharStyle,
                      charStyles = app.selection[0].characters.everyItem().appliedNestedStyles,
                      step = charStyles.length,
                      resString = "";
                    
                      while ( (cCharStyle = charStyles.pop() ) && step--)
                           if ( cCharStyle.length )
                                resString = app.selection[0].characters[step].contents + resString;
                    
                    alert ( resString );
                    

                     

                    Jarek

                    • 7. Re: Find nested characters and apply the Cstyle
                      selvam214 Level 1

                      Hi Jarek,

                      The provided codes support perfectly, i'll share the additional test result to you shortly.

                       

                       

                      Thanks for the effort.

                      Selva

                      • 8. Re: Find nested characters and apply the Cstyle
                        selvam214 Level 1

                        Hi Jarek,

                        If possible to find the nested overrides?

                         

                        Example: in 1st sample (black screenshot with in this thread), the first line fixed (applied) in nested style with small cap, but the italic is override (AN ... WARM.).  How to find this occurrence.