5

我正在编写一些 JS 代码来重新链接图像,然后调整它的大小以适合包含的对象。简化版代码:

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;
}

使用块周围的 try/catch 块if(image.locked),调整大小行会引发错误“图像已锁定”(因为它无法解锁它)。如果没有 try/catch 但保留if(image.locked)块,则会引发错误“该属性不适用于当前状态。” 尝试访问时image.locked

那么我的图像处于什么“状态”,为什么即使应用程序清楚地使用它来阻止我调整它的大小,它也不是“适用的”?鉴于这是一个自动化过程并且在生产中我无法访问 InDesign 以事先手动编辑它,我该如何调整图像大小?

4

1 回答 1

5

如 Adob​​e 的文档中所述,图像容器——“围绕”图像的父框架,它是一个通用的SplineItem——可以通过更改读/写布尔属性来锁定和解锁locked

在 InDesign CS4 及更早版本中,Graphic类没有此属性,但自 InDesign CS5 起,该属性locked也出现在其中及其所有派生类中。根据 Adob​​e 的文档,它是一个读/写属性。然而,这似乎是错误的。用CS6做实验,发现locked一个图形在其父框架内的属性只反映了父级的状态,实际上是只读的

In the InDesign user interface in CS4 and earlier, the menu item "Lock" is disabled when a graphic inside a frame is selected. 在 CS5 及更高版本的用户界面中,无法选择锁定的项目,因此无法调用菜单项。

给定图形图像的句柄,最简单的解决方法是通过其父项检查和/或更改状态:

image = app.activeDocument.allGraphics[0]; // a handle to the first graphic
image.parent.locked = false; // unlock it
于 2014-10-03T11:33:44.430 回答