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;
Again: In line 11 of the first script you have
var letztArt = Auswahl
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.
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
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".
Copy link to clipboard
Copied
Again: In line 11 of the first script you have
var letztArt = Auswahl
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.
Copy link to clipboard
Copied
Okay. Sorry, now I´ve got it: I have to use
var letztArt = eineAuswahl
Thank you! Now it works.
Copy link to clipboard
Copied
Hi,
So....:
var letztArt = eineAuswahl
.paragraphs.item(- 2);
TaW pointed the error
Jarek