5 Replies Latest reply on Jun 23, 2016 8:39 AM by Silly-V

    Looping through all items on a page

    Bob Haslett

      I am trying to create a script that loops through all the textand path items on a page, sets some text attributes and depending on the name of the item group it with others of the same name. The script I have at the moment sometimes works and sometimes doesn't. It always sets the text attributes, but sometimes will only move say 4 of the seven items with the name xAxisLabel to the group xLabels, other times it will move 3 or 5. Its the same with the path items also, really can't work this out and would appreciate any help

       

       

      //Selects the graph before to scale them and turns off the pixel align so that values of 1 decimal place can be applied to strokes

      doc.selectObjectsOnActiveArtboard(); 

      var sel = doc.selection;

      sel.pixelAligned=false

       

       

      var item

       

       

      var xLabels = layer.groupItems.add();  //create group for xAxis

      var yLabels = layer.groupItems.add();  //create group for xAxis

      var yTicks = layer.groupItems.add();  //create group for xAxis

       

       

      //Loops through  ungrouped text items and set horizontal scale, spot black and tabular lining on figures

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

          item=layer.textFrames[i];

          $.writeln (item)

          item.textRange.characterAttributes.textFont = textFonts.getByName("Metric-Regular");

          item.textRange.characterAttributes.figureStyle=FigureStyleType.TABULAR

          item.textRange.characterAttributes.fillColor=myBlack;

         

          //move labels on xAxis into the same group

          if (item.name=="xAxisLabel") {

               item.moveToEnd(xLabels);

           }

       

          //move labels on yAxis into the same group

           if (item.name=="yAxisLabel") {

                  item.moveToEnd(yLabels);

           };

       

      };