5 Replies Latest reply on Oct 24, 2016 2:09 PM by cmoke73

    Assigning a paragraph-style in a loop

    cmoke73 Level 1

      Hi everybody.

       

      I have a simple task: select some items in a document and assign to the penultimate paragraph a style in a for-loop.

      var doc = app.documents;  
      var Auswahl = app.selection[0];
      var eineAuswahl = app.selection;
      var Anzahl = Auswahl.paragraphs.count();
      var Durchgaenge = eineAuswahl.length;
      
      for (var x=0; x<Durchgaenge; x++) {
          //alert (eineAuswahl[x].paragraphs.count());
              var FormGrup_SF_Artikel = app.activeDocument.paragraphStyleGroups.itemByName('SF_Artikel');
              var AbsForm_SF_Art_Tx_2_Abst = FormGrup_SF_Artikel.paragraphStyles.itemByName('SF_Artikel_Text_2_Artikel_mehr Abstand');
              var letztArt = Auswahl[x].paragraphs.item(-2);        
              letztArt.appliedParagraphStyle = AbsForm_SF_Art_Tx_2_Abst;  
      }
      

       

      After running the script it stops. The error-message ist: "Object does not support the property or method '0'". What does it mean?

      When it runs without a loop (assign only to one object), it works:

       

       var FormGrup_SF_Artikel = app.activeDocument.paragraphStyleGroups.itemByName('SF_Artikel');
              var AbsForm_SF_Art_Tx_2_Abst = FormGrup_SF_Artikel.paragraphStyles.itemByName('SF_Artikel_Text_2_Artikel_mehr Abstand');
              var letztArt = Auswahl.paragraphs.item(-2);        
              letztArt.appliedParagraphStyle = AbsForm_SF_Art_Tx_2_Abst;