首页 > 解决方案 > Adobe InDesign Javascript 错误!错误号:55 错误字符串:对象不支持属性或方法“documentPreferences”

问题描述

当我尝试在 InDesign 中运行以下代码时出现错误。我实际上是直接从 Adob​​e 教程中获取此代码的,不知道他们为什么会弄错自己的代码。任何您能提供帮助的方式将不胜感激!谢谢。

try{myFont = app.fonts.item("Arial");
   }
catch (myError){};
var myDocument = app.documents.item(0);

with(myDocument){

    var myPage = pages.item(0);
    var myBounds = myGetBounds(myPage,myDocument);

    with(myDocument.pages.item(0)){
        //Get a reference to the text frame.
        var myTextFrame = textFrames.item(0);
        //Change the size of the text frame.
        myTextFrame.geometricBounds = myBounds;
        var myParagraph = myTextFrame.paragraphs.item(0);
        myParagraph.appliedFont = myFont;
        myParagraph.justification = Justification.centerAlign;
        myParagraph.pointSize = 48;
    }

}
    //myGetBounds is a function that returns the bounds 
    //of the "live area" of a page.
function myGetBounds(myDocument, myPage){
    var myPageWidth = myDocument.documentPreferences.pageWidth;
    var myPageHeight = myDocument.documentPreferences.pageHeight;

    if(myPage.side == PageSideOptions.leftHand){
        var myX2 = myPage.marginPreferences.left;
        var myX1 = myPage.marginPreferences.right;
    }else{
        var myX1 = myPage.marginPreferences.left;
        var myX2 = myPage.marginPreferences.right;
    }
    var myY1 = myPage.marginPreferences.top;
    var myX2 = myPageWidth - myX2;
    var myY2 = myPageHeight - myPage.marginPreferences.bottom;
    return [myY1, myX1, myY2, myX2];
}

标签: javascriptadobe-indesign

解决方案


看起来在myGetBounds()函数中您以错误的顺序传递参数。

在函数定义中,您可以看到应该首先传递文档,然后再传递页面,但在从var myBounds您开始的行中则相反。

所以这条线应该是:

var myBounds = myGetBounds(myDocument, myPage);

推荐阅读