2 Replies Latest reply on Oct 22, 2015 12:11 AM by Lev Ger

    A better way to get all text style ranges into one array

    Lev Ger Level 1

      I am trying to get all the text style ranges of my document into one array. I am scripting in JavaScript, which I am not very familiar with so this might be the problem.

       

      Here is what I think should work:

      app.activeDocument.stories.everyItem().textStyleRanges
      

      The above only gives me a string of text, not an array of text style objects as I expected. If I were using Applescript I could just ask for the object reference of the text style ranges, but this is not a property I have found in the javascript object model.

       

      So I resorted to this, which is slower, but does give me what I want:

      var allStyleRanges = new Array();
      for (var g = 0; g < myStories.length; g++) {
        var storyStyleRanges = (myStories[g].textStyleRanges);
        for (var s = 0; s < storyStyleRanges.length; s++) {
        allStyleRanges.push(storyStyleRanges[s]);
        };
      };
      

       

      Does anyone have a better way?