• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Assigning a paragraph-style in a loop

Engaged ,
Oct 24, 2016 Oct 24, 2016

Copy link to clipboard

Copied

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.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.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; 

TOPICS
Scripting

Views

342

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Oct 24, 2016 Oct 24, 2016

Again: In line 11 of the first script you have

     var letztArt = Auswahl.paragraphs.item(-2);         

The first time the loop is entered, x = 0.

So you're trying to access this property:

app.selection[0][0]

That property does not exist. Hence the error message.

Votes

Translate

Translate
People's Champ ,
Oct 24, 2016 Oct 24, 2016

Copy link to clipboard

Copied

In the first script, you have

letztArt = Auswahl

but

Auswhal = app.selection[0];

so what do you mean by

app.selection[0][0]

when x == 0 ??

Try it without the !

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 24, 2016 Oct 24, 2016

Copy link to clipboard

Copied

I need the var x to change the paragraph in EACH of the selected text frames. If I try without it changes only the first of the selected objects. x stands for "next selected object".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 24, 2016 Oct 24, 2016

Copy link to clipboard

Copied

Again: In line 11 of the first script you have

     var letztArt = Auswahl.paragraphs.item(-2);         

The first time the loop is entered, x = 0.

So you're trying to access this property:

app.selection[0][0]

That property does not exist. Hence the error message.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 24, 2016 Oct 24, 2016

Copy link to clipboard

Copied

LATEST

Okay. Sorry, now I´ve got it: I have to use

var letztArt = eineAuswahl.paragraphs.item(-2);

Thank you! Now it works.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Oct 24, 2016 Oct 24, 2016

Copy link to clipboard

Copied

Hi,

So....:

var letztArt = eineAuswahl.paragraphs.item(-2);

TaW pointed the error

Jarek

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines