简体   繁体   English

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

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

I've got the following problem/situation: 我有以下问题/情况:

  • 12-page document (ID CC 2015) 12页文件(ID CC 2015)
  • one frame with a greyscale picture per page 一页,每页有一个灰度图片
  • the pictures are colored with the same color swatch (eg "universal") on all pages (white arrow, applied color swatch) 所有页面上的图片都使用相同的颜色样本(例如“通用”)进行着色(白色箭头,应用颜色样本)

What I want to do now, is to write a script to color every picture with a different color swatch, eg the picture on page 1 with color swatch "1", the picture on page 2 with color swatch "2" etc. But I don't know how to access the picture itself (instead of the frame) and change its color. 我现在要做的是编写一个脚本,用不同的颜色样本为每张图片着色,例如第1页上的图片,色样“1”,第2页上的图片,色样“2”等。但是我不知道如何访问图片本身(而不是框架)并改变其颜色。 Is this even possible? 这甚至可能吗?

Thanks in advance. 提前致谢。

This should do the trick. 这应该可以解决问题。 It currently sets random color for the images and only looks for rectangles. 它目前为图像设置随机颜色,仅查找矩形。 You could use 你可以用

page.allPageItems

instead. 代替。 (if you also have images in ovals or polygons) (如果你还有椭圆形或多边形的图像)

// 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Extendscript (JavaScript) 以增量方式更改 Indesign 色板 - Changing an Indesign Swatch incrementally with Extendscript (JavaScript) "是否可以使用 CEP\/ExtendScript\/JS 检测 InDesign 中的页面更改?" - Is it possible to detect the change of page in InDesign using CEP/ExtendScript/JS? 使用色板名称在Photoshop中删除色板 - Delete color swatch in Photoshop using name of swatch 使用extendscript更改对象的颜色 - Change the color of objects with extendscript 如何在Adobe Indesign的extendscript中定义换行符 - How to define a line break in extendscript for Adobe Indesign 如何使用ExtendScript从InDesign文档中的所有脚注引用中删除斜体和粗体样式? - How can I remove italic and bold styling from all footnote references in an InDesign document using ExtendScript? 如何使用Javascript将对应的图像插入色样? - How to insert the corresponding image to color swatch using Javascript? 将ExtendScript添加到Indesign中的按钮 - Add a ExtendScript to a button in Indesign 使用Extendscript在InDesign中放置文件时指定编码 - Specifying Encoding While Placing Files In InDesign Using Extendscript Extendscript InDesign CS6:使用打印预设进行打印 - Extendscript InDesign CS6: Print using a print preset
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM