I am intermediate with Javascript, but am not so familiar with Adobe’s “Extendscript”. For practice and a better understanding of InDesign’s code structure, I am trying to access properties of an image via rectangles.images.
Is this possible to access say, the file name of an image, through rectangles.images? Also I am interested if it’s possible to access the image’s color attributes this way, say to convert it to greyscale?
Here is my approach so far:
for(var i = 0; i < app.activeDocument.rectangles.length; i++)
{
var imageType = app.activeDocument.rectangles[i].images.constructor.name;
switch(imageType)
{
case "Images":
alert(app.activeDocument.rectangles[i].images.name); // "name" is not a valid property here!
break;
default:
alert("There are no images in this file.");
}
}
Also, is it possible to determine the file-type of the image with .rectangles.images.constructor.name? I would like to add an extra case for say, PDF’s or jpegs.
You shouldnt use the constructor unless you want to try and determine what type of JS Object it is which you dont need to do in this case because the
imagescollection is only going to contain images. The file property will actually be on an image’s relatedLinkobject.Note none of this is tested i jsut took my knowledge of JS and the API documentation and reworked your code…