如何在 InDesign 中使用 ExtendScript 更改彩色灰度图片的色样?

How to change color swatch of colored greyscale pictures using ExtendScript in InDesign?

我有以下 problem/situation:

我现在想做的是写一个脚本,用不同的色样给每张图片上色,例如第 1 页上的图片带有色样“1”,第 2 页上的图片带有色样“2”等。 但我不知道如何访问图片本身(而不是框架)并更改其颜色。这可能吗?

提前致谢。

这应该可以解决问题。 它目前为图像设置随机颜色并且只寻找矩形。你可以使用

page.allPageItems

相反。 (如果您还有椭圆形或多边形图像)

// the main function
var main = function() {
  var doc = app.activeDocument; // get the current document
  // loop the pages
  for (var i = 0; i < doc.pages.length; i++) { 
    var page = doc.pages[i]; // isolate the page
    // loop all rectangles
    for(var j = 0; j < page.rectangles.length;j++){
      var rect = page.rectangles[j]; // isolate a rectangle
      // test if there is an image inside
      if(rect.images.length > 0){
        var image = rect.images[0]; // isolate the image
        // asign a random color from th swatches
        image.fillColor = doc.swatches[Math.floor(Math.random()* doc.swatches.length -1)];
      } // end if image
    } // end loop j rectangles
  } // end loop i pages
} // end of main
main(); // run it