0

I try to loop through a selection to modify the fill color of the the selected items in InDesign using ExtendScript. Some of the selected items are grouped.

var mySelection = app.selection;
for (var myIndex in mySelection) {
    var myPageItem = mySelection[myIndex];
    myPageItem.fillColor = app.activeDocument.swatches.item("Black");
}

The fill color of the selected items is not modified.

How can I loop through a selection to modify the fill color of the the selected items in InDesign using ExtendScript?

I thank you for your help.

alex
  • 1
  • 1
  • check out the answer here for hints on referencing items in a selection https://stackoverflow.com/questions/29908569/how-to-use-app-selection0-for-scripts-in-adobe-indesign – user1754036 Nov 15 '22 at 22:13

1 Answers1

0

I see no problem to recolor groupped items with this snippet. But I see the problem with in in the 'for' loop definition.

This line doesn't work for me:

for (var myIndex in mySelection) {

This line works:

for (var myIndex=0; myIndex<mySelection.length; myIndex++) {

Extendscript is an old outdated version of Javascript. In Extendscript operator in doesn't work with arrays in the way as it does in the modern Javascript. It works with object's keys only. So in your example var myIndex in mySelection is zero and the loop doesn't start.

Yuri Khristich
  • 13,448
  • 2
  • 8
  • 23