I am writing some JS code to relink an image, then resize it to fit the containing object. Simplified version of code:
var image = (get image);
try {
image.itemLink.relink(File(new_filename));
}
catch(e) {
(log it);
}
var image = (find image again because after the relink it would otherwise cause error "Object no longer exists")
(work out new width, height, v offset, h offset);
try {
if(image.locked) {
lock_later = true;
image.locked = false;
}
}
catch(e) { }
// Resize and reposition image
image.geometricBounds = [(rectangle.geometricBounds[0] + h_offset) + "mm", (rectangle.geometricBounds[1] + w_offset) + "mm", (rectangle.geometricBounds[2] - h_offset) + "mm", (rectangle.geometricBounds[3] - w_offset) + "mm"];
// Lock the image again if it was locked before
if(lock_later) {
image.locked = true;
}
With the try/catch block around the if(image.locked)
block, the resize line throws the error "Image is locked" (because it fails to unlock it). Without the try/catch but keeping the if(image.locked)
block, it throws the error "The property is not applicable in the current state." when trying to access image.locked
.
So what "state" is my image in, and why is it not "applicable" even though the app is clearly using it to prevent me resizing it? How do I resize my image, given that this is an automated process and in production I won't have access to InDesign to edit it manually beforehand?