2013-05-13 4 views
0

저는 꽤 새로운 프로그래머입니다. 그러니 나와 함께하시기 바랍니다. 나는 꽤 발전된 것을 시도하고 있지만, 나는 좋은 도전을 즐긴다. : ~) 저는 Adobe의 ESTK (ExtendScript Toolkit)을 사용하여 InDesign CS6 용 복잡한 스크립트를 작성하고 있습니다. 나는 대부분의 자습서를 거쳤으며 꽤 많은 것을 배웠다. 그러나 나는 지금 벽에 뛰어 들었다.서브 디렉토리에있는 여러 파일을 여는 자바 스크립트 코드

특정 폴더가 특정 기준을 충족하는지 여부를 검색하고, 그럴 경우 해당 폴더를 파헤 치기 위해 해당 하위 폴더를 모두 계산하고 각 하위 폴더에서 .indd 파일 각각을 여는 스크립트가 필요합니다. 차례대로 각 작업을 수행합니다. 입력 된 주문 번호 인 경우

var getDataDialog = app.dialogs.add({name:"Job Info"}); 
with(getDataDialog){ 
    // Add a dialog column. 
    with(dialogColumns.add()){ 
     // Create the order number text edit box. 
     var orderNumTextEditBox = textEditboxes.add({minWidth:80}); 
     } 
    } 
// Show the dialog box. 
var dialogResult = getDataDialog.show(); 
if(dialogResult == true){ 
    // Get the order number and put it in the variable "orderNum". 
    var orderNum = orderNumTextEditBox.editContents; 
    // Get the first three numbers of the order number and put it in "orderPrefix". 
    var orderPrefix = orderNum.substr(0,3); 
    // Remove the dialog box from memory. 
    getDataDialog.destroy(); 
    // Store the folder prefix into "folderPrefix". 
    var folderPrefix = "/g/ ArtDept/JOBS/" + orderPrefix + "000-" + orderPrefix + "999/" 
    // Open the document with the order number. 
    var myDoc = app.open(File(folderPrefix + orderNum + " Folder/" + orderNum + ".indd"), true); 
    } 
else{ 
    getDataDialog.destroy(); 
    } 

그래서, "405042"으로는 "405000-405999"폴더에 볼 것이다 : 나는 단지 오늘 스크립트를 시작했습니다 이것은 내가 지금까지있어 무엇인가 그런 다음 "405042 Folder"라는 패키지 폴더에 넣은 다음 그 안에 .indd 파일을 엽니 다. 문제는 폴더 내에 여러 패키지가있는 경우가 있습니다. 내가 스크립트가 차례로 그 각각의 파일을 열고 자하는 것이다

405000-405999/405007/405007_N10/405007_N10.indd 
405000-405999/405007/405007_C12/405007_C12.indd 
405000-405999/405007/405007_Orange/405007_Orange.indd 

, 그들에 대한 몇 가지 작업을 수행 : 예를 들어, 우리는있을 수 있습니다. 나는 그것이 가능하다는 것을 확신하지만, 단지 그것을 코딩하는 방법을 알 필요가있다. 더 많은 정보가 필요하시면 기꺼이 알려주십시오. 기꺼이 제공해 드리겠습니다. 고맙습니다!

제 1 부 : 특정 폴더 회의 특정 기준을 찾기 내가 제대로 문제를 이해한다면

+1

귀하의 주제는 이미 꽤 복잡하다. 그래서 간단한 대답은 없습니다. 수정 ExtendScript http://jongware.mit.edu/Js/pc_File에서 자바 스크립트 http://www.codecademy.com/courses/javascript-lesson-205 파일에 재귀 : 당신은이 일에보고해야한다. 수정 ExtendScript http://jongware.mit.edu/Js/pc_Folder.html 조금 도움이 희망의 HTML 폴더. – fabianmoronzirfas

+0

디렉토리 구조를 조금 더 그려 낼 수 있습니까? –

+0

링크를 보내 주셔서 감사합니다. @ fabiantheblind; 시간이 있고 곧 더 배우기를 바랍니다. 예, 이것은 분명히 복잡한 대본이 될 것입니다. 그래서 그것은 불의 재판입니다. – Sturm

답변

2

는 두 부분이 있습니다. (당신이 덮여있어처럼 보인다.)

제 2 부 :이 폴더의 하위 각 InDesign 문서의 경우,을 열고 몇 가지 처리를 할. 당신이 상위 폴더와 각 문서를 조작하는 코드를 발견 한 코드를 추가 할 위치 아래, 내가 표시 한 샘플에서

. 샘플을있는 그대로 실행하면 스크립트의 상위 폴더가 최상위 폴더로 사용되며 각 하위 문서의 경우 해당 이름이 기록됩니다.

// TODO: (Part 1) Put code here that determines the top folder. 
var topFolder = (new File($.fileName)).parent; // Change me. Currently the script's folder. 
forEachDescendantFile(topFolder, doStuffIfdocument); // Don't change this line. 

/** 
* Does stuff to the document. 
*/ 
function doStuff(document) { 
    // TODO: (Part 2) Put code here to manipulate the document. 
    $.writeln("Found document " + document.name); 
} 

/** 
* Opens the given file if it ends in ".indd". Then calls doStuff(). 
* 
* @param {File} oFile 
*/ 
function doStuffIfdocument(oFile) { 
    if (matchExtension(oFile, "indd")) { 
     var document = app.open(oFile); 
     try { 
      doStuff(document); 
     } 
     finally { 
      document.close(SaveOptions.YES); 
     } 
    } 
} 

/** 
* Calls the callback function for each descendant file of the specified folder. 
* The callback should accept a single argument that is a File object. 
* 
* @param {Folder} folder The folder to search in. 
* @param {Function} callback The function to call for each file. 
*/ 
function forEachDescendantFile(folder, callback) { 
    var aChildren = folder.getFiles(); 
    for (var i = 0; i < aChildren.length; i++) { 
     var child = aChildren[i]; 
     if (child instanceof File) { 
      callback(child); 
     } 
     else if (child instanceof Folder) { 
      this.forEachDescendantFile(child, callback); 
     } 
     else { 
      throw new Error("The object at \"" + child.fullName + "\" is a child of a folder and yet is not a file or folder."); 
     } 
    } 
} 

/** 
* Returns true if the name of the given file ends in the given extension. Case insensitive. 
* 
* @param {File} iFile 
* @param {String} sExtension The extension to match, not including the dot. Case insensitive. 
* @return {boolean} 
*/ 
function matchExtension(iFile, sExtension) { 
    sExtension = "." + sExtension.toLowerCase(); 
    var displayName = iFile.displayName.toLowerCase(); 
    if (displayName.length < sExtension.length) { 
     return false; 
    } 
    return displayName.slice(-sExtension.length) === sExtension; 
} 
+0

JavaScript/ExtendScript를 처음 접하는 사람이라면 코드를 내 프로그램에 맹목적으로 붙여 넣기 전에 코드를 조사해 볼 수 있어야합니다. – Sturm

+0

@Sturm 항상 현명한 결정. 권장 사항 : 시작부터 끝까지 코드 경로를 따르려고하는 대신 각 기능을 개별적으로 살펴보고 주석의 내용을 확인하십시오. 그렇게 간단합니다. – dln385

+0

나는 많은 질문이 있지만, 지금 당장 시작하겠습니다. 3 행에서, forEachDescendantFile 함수를 호출 할 때 두 번째 인수는 함수입니다. 괜찮습니다. 그러나 함수에 인수를 전달해서는 안됩니까? 실수가 아니라면'{File}'형식 인수가 필요합니다. – Sturm

관련 문제