สคริปต์ Indesign jsx กำลังร้องขอตัวชี้

ฉันยังใหม่กับการเขียนสคริปต์ indesign ฉันต้องการคำแนะนำในการเขียนสคริปต์ jsx ฉันมีเทมเพลต indesign (ไฟล์ indt) และฉันต้องสร้างไฟล์ indd จากมัน (เพียงสำเนา) จากนั้นฉันต้องแทนที่ชื่อ/นามสกุลและวันที่ ฯลฯ ด้วยเนื้อหาที่ฉันอ่านจาก xml

จนถึงตอนนี้ฉันชอบสิ่งนี้:

function buildIndesignDocument(templatePath, templateFileName, targetPath, xmlFile, orderNumber, jobNumber) {
    DEBUGG("buildIndesignDocument execution start");

    //check wheher target path is writable.  If not exit from further processing
    var canSaveToServerFlag = checkServerWritable(targetPath.toString());
    if(!canSaveToServerFlag) {
        DEBUGG("Exiting from the process");
        return;
    }else{
        var originalTemplateFilePath = templatePath+templateFileName;
        DEBUGG("Original Template Path is " + originalTemplateFilePath);
        var originalTemplate = new File(originalTemplateFilePath);
        var filePrefix =jobNumber.toString()+"_"+orderNumber.toString()+ "_";

        if (originalTemplate.exists) {
            //create a copy of the template in target folder and name it as indd
            targetFileName= filePrefix+templateFileName.replace(".indt", ".indd");
            DEBUGG("target FileName is " + targetFileName);
            var targetFile =targetPath.toString() + targetFileName ;
            DEBUGG("target FilePath and name is " + targetFile);
            var targetFileCreated=originalTemplate.copy(File(targetFile));
            //  if(targetFileCreated.exists){
                // TODO####hardcoded true need to change
                if(true) {
                    DEBUGG("targetFile Created Successfully" + targetFileCreated);

                    var xmlFormFile =getGenericXmlFile(xmlFile);
                    DEBUGG("xmlFormFile is -----------" +xmlFormFile);
                    var firstName = xmlFormFile.xpath("/formData/firstName");
                    var lastName = xmlFormFile.xpath("/formData/lastName");
                    DEBUGG("firstName----------"+firstName  + "  and last name is ----------" +lastName );

                    //Open the indd file and replace the content with form data preserving format and style
                    var inddFile = new File(targetFile);
                    try {
                        DEBUGG("inside try");

                        //open file for write -mode w is write
                        inddFile.open ("w", null, null);
                        var myDoc=inddFile.read ();
                        DEBUGG("after opening"+myDoc.toString());

                        inddFile.close;
                    } catch(e) {
                        DEBUGG("Exception in opening " + e.description);
                        inddFile.close;
                    }
                } else {
                    DEBUGG("targetFile did not create successfully");
                }
            } else {
                DEBUGG("Template not Found");   
                logError("Missing template file with name =="  +originalTemplateFilePath);
            }
            DEBUGG("buildIndesignDocument execution end");
        }
    }
}

ฉันไม่สามารถเปิดไฟล์ได้อย่างถูกต้องและแทนที่เนื้อหาได้ ใครสามารถให้ความกระจ่างเกี่ยวกับเรื่องนี้ได้บ้าง


person DesignJoe    schedule 14.08.2018    source แหล่งที่มา
comment
คุณได้ลองเปิดไฟล์ที่ซ้ำกัน/เปลี่ยนชื่อด้วยตนเองแล้วหรือยัง? ถ้าใช่มันได้ผลเหรอ? จะเกิดอะไรขึ้นถ้าคุณใช้ var myDocument = app.open(File(targetFile))?   -  person cybernetic.nomad    schedule 15.08.2018
comment
ฉันทำแล้วแต่มันบอกว่าไม่รู้จัก app.open ฉันใช้ ExtendedToolKit เพื่อรันสคริปต์ ฉันควรทำอย่างอื่นด้วย   -  person DesignJoe    schedule 15.08.2018
comment
ใน ExtendedToolKit ตรวจสอบให้แน่ใจว่าคุณเลือก Indesign ในเมนูด้านซ้ายบนหรือเพิ่ม #target InDesign เป็นบรรทัดแรกของสคริปต์ของคุณ   -  person Nicolai Kant    schedule 17.08.2018


คำตอบ (1)


หากต้องการเปิดเทมเพลตและบันทึก ให้ลองทำดังนี้:

function buildIndesignDocument(templatePath, templateFileName, targetPath, xmlFile, orderNumber, jobNumber) {
        var myDocument = app.open(File(templatePath+"/"+templateFileName));

// do what you want with the document here

        var targetFileName= targetPath+"/"+templateFileName.replace(".indt", ".indd");
        myDocument.save(new File(targetFileName));
 }
person cybernetic.nomad    schedule 16.08.2018