我为 inDesign 开发了一个脚本,它逐页循环 inDesign 文件,扫描文本框架,查找文本中的特定代码,并针对每个代码检查该代码是否在列表中,如果是,则脚本将在代码后插入一个小图像,如果没有,脚本将传递到下一个文本框架。
因为例子胜于大话,所以这里有一个例子:
在代码之后插入了这个小的黑色/灰色图像。这对于每个代码都完美适用,除了最后一个表行上的代码。
在寻求帮助之前我已经检查了几点: - 脚本正确检测代码(我什至可以使用脚本编辑文本以确保)。 -表格单元格有足够的空间来插入图像(我也尝试为行提供更高的高度)。 -我尝试调整图像大小,使其变小。 -如果我在最后一行后添加一个空行,脚本会正确添加图像...所以这确实是最后一行问题...
现在这是脚本失败的部分
app.findTextPreferences.findWhat = currentREF;
var myFoundItems = app.activeDocument.findText();
for ( var bh = 0; bh < myFoundItems.length; bh++ ) {
myLastIns = myFoundItems[bh].insertionPoints.length;
myInsPointOk = myFoundItems[bh].insertionPoints[myLastIns - 1];
if ( bh == 0 ) {
myTf = myInsPointOk.parentTextFrames[0];
}
try {
//Insert/place the logo
var myImgPath = logoImage;
var myBlockImg = myInsPointOk.rectangles.add( {strokeWeight: 0, strokeColor: "None", fillColor: "None", geometricBounds: [ 0, 0, 1, 1 ]} );
myBlockImg.contentType = ContentType.graphicType;
myBlockImg.anchoredObjectSettings.anchoredPosition = AnchorPosition.INLINE_POSITION;
myBlockImg.anchoredObjectSettings.anchorXoffset = 0;
myBlockImg.anchoredObjectSettings.anchorYoffset = 0;
myBlockImg.place( File( myImgPath ) );
myBlockImg.fit( FitOptions.FRAME_TO_CONTENT );
} catch ( e ) {
//Warning, the code has been find but the script didn't success to insert it
$.writeln( "La référence " + normalFormatRef + " à été trouvée dans le fichier " + app.activeDocument.name + " mais le script n'à pas réussit à insérer le picto." );
arrError.push( "La référence " + normalFormatRef + " à été trouvée dans le fichier " + app.activeDocument.name + " mais le script n'à pas réussit à insérer le picto." );
}
}
我猜脚本在最后一行的表中找不到插入点...但为什么呢? 或者也许我猜错了......
最后,每次尝试在最后一行添加图像时,脚本都会停止在该行...
var myBlockImg = myInsPointOk.rectangles.add( {strokeWeight: 0, strokeColor: "None", fillColor: "None", geometricBounds: [ 0, 0, 1, 1 ]} );
这就是为什么我猜测是插入点失败了。
最佳答案
首先感谢您的解答! 然后我终于找到了解决方案,我发布在下面:
if ( myFoundItems[bh].parent.constructor.name == "Cell" ) {
//Only for text include in cells, temporary increase the height of the parent's row
var previousRowHeight = myFoundItems[bh].parent.minimumHeight;
myFoundItems[bh].parent.minimumHeight = "15mm";
myFoundItems[bh].parent.parent.parent.fit( FitOptions.FRAME_TO_CONTENT );
}
var myBlockImg = myFoundItems[bh].parent.insertionPoints[-1].rectangles.add( {strokeWeight: 0, strokeColor: "None", fillColor: "None", geometricBounds: [ 0, 0, 0.1, 0.1 ]} );
myBlockImg.contentType = ContentType.graphicType;
myBlockImg.anchoredObjectSettings.anchoredPosition = AnchorPosition.INLINE_POSITION;
myBlockImg.anchoredObjectSettings.anchorXoffset = 0;
myBlockImg.anchoredObjectSettings.anchorYoffset = 0;
myBlockImg.place( File( myImgPath ) );
myBlockImg.fit( FitOptions.FRAME_TO_CONTENT );
if ( myFoundItems[bh].parent.constructor.name == "Cell" ) {
//Only for text include in cells, reset the height of the parent's row
myFoundItems[bh].parent.minimumHeight = previousRowHeight;
myFoundItems[bh].parent.parent.parent.fit( FitOptions.FRAME_TO_CONTENT );
}
解释一下,我发现增加行的高度是不够的,它还需要适合父级的文本 block 。
关于javascript - InDesign 脚本 - 表格页脚和插入点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36359774/