[英]get current text frame width in indesign script
下面的代碼獲取我的文檔中的第一個文本框寬度。 如何在 Indesign 腳本中獲取活動文本框寬度? 圖片顯示了我的問題。
function freamWidth() {
var frameRef = app.documents[0].textFrames[0];
var gBounds = frameRef.geometricBounds;
var y0 = gBounds[0];
var x0 = gBounds[1];
var y1 = gBounds[2];
var x1 = gBounds[3];
//do calculations
var frameWid = x1 - x0;
// var frameHgt = y1 - y0;
return frameWid;
}
這更多的是如何檢索選擇的父文本框的問題。 您通常可以通過文本選擇的parentTextFrames
屬性執行此操作。 您還可以選擇檢查是否選擇了文本框架本身而不是文本框架中的某些文本。 因此,以下代碼應該適用於您的場景:
var tf;
var sel = app.selection[0];
if(sel.hasOwnProperty('baseline')) {
tf = sel.parentTextFrames[0];
} else if (sel instanceof TextFrame) {
tf = sel;
}
var tfWidth = tf.geometricBounds[3] - tf.geometricBounds[1];
alert("The text frame width is " + tfWidth);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.