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

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

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];
}
ttzzhhssjjnn 回答:Adobe InDesign Javascript错误!错误号:55错误字符串:对象不支持属性或方法“ documentPreferences”

myGetBounds()函数中,您似乎以错误的顺序传递了参数。

在函数定义中,您可以看到应该先​​传递文档,然后再传递页面,但是在以var myBounds开头的行中,您可以采用其他方法。

所以该行应该是:

var myBounds = myGetBounds(myDocument,myPage);
本文链接:https://www.f2er.com/2945370.html

大家都在问