2 Replies Latest reply on Jan 30, 2017 10:45 AM by Laubender

    Problem (or bug?) with method remove() by collection of nestedGrepStyles

    Laubender Adobe Community Professional & MVP

      Hi together,

      I think I found a bug with method remove() for nestedGrepStyles with paragraphStyles.

       

      I want to remove all nested Grep styles in a paragraph style.

       

      This will not work:

       

      var doc = app.documents.add();
      var paraStyle = doc.paragraphStyles.add();
      for(var n=0;n<4;n++)
      {
          paraStyle.nestedGrepStyles.add();
      };
      
      try
      {
          paraStyle.nestedGrepStyles.everyItem().remove();
      }
      catch(e)
      {
          $.writeln(e);
      };
      
      // Error: Die angeforderte Aktion konnte nicht ausgeführt werden, da das Objekt nicht mehr existiert.
      // $ID/ObjectDeletedError
      

       

       

      However what is working:

      A loop through the array of nested Grep styles to remove them

       

      var doc = app.documents.add();
      var paraStyle = doc.paragraphStyles.add();
      for(var n=0;n<4;n++)
      {
          paraStyle.nestedGrepStyles.add();
      };
      
      var nestedGrepStylesArray = paraStyle.nestedGrepStyles.everyItem().getElements();
      var arrayLength = nestedGrepStylesArray.length;
      
      for(var n=arrayLength-1;n>=0;n--)
      {
          nestedGrepStylesArray[n].remove();
      };
      

       

       

      Tested with InDesign CC 2017 v12.0.0.81 on Mac OSX 10.10.5.

       

      Can someone confirm this?

       

      Regards,
      Uwe

       

      FWIW: I cannot create tags with camel-case writing like nestedGrepStyles or everyItem().
      Oh Jive! That's ridiculous…