2011-02-08 6 views
1

ExtendScript를 사용하여 InDesign을 스크립팅하려고합니다. 스크립트가 선택한 텍스트를 잘라내 각주를 삽입하고 텍스트를 각주 본문에 붙여 넣기를 원합니다. 나는 시도하는 것 :선택한 텍스트에서 각주 생성

function makeFootnoteOfSelection(){ 
    var fnText = app.activeDocument.selection[0]; 
     // this should actually clone the selected text, not reference it, because the next statement zaps it from memory 
    app.activeDocument.selection[0].remove(); // works 
    var fNote = app.activeDocument.selection[0].footnotes.add(); // works, adds an empty footnote with a reference 
    fNote.contents = fnText.contents; 
     // this replaces the reference number, I was hoping to retain it and just add the text 
     // fNote.contents += fnText.contents; also replaces the reference number 
} 

답변

5

인디자인 CS5 :

function makeFootnoteOfSelection(){ 

    // Reference the selection 
    var fnText = app.activeDocument.selection[0]; 

    // Add an empty footnote where the selected text is 
    var fNote = app.activeDocument.selection[0].footnotes.add(); 

    // Move the selected text at the end of the empty footnote 
    fnText.move(LocationOptions.AFTER, fNote.insertionPoints[-1]); 
} 

인디자인 CS4를 :와

function makeFootnoteOfSelection(){ 

    // Reference the selection 
    var fnText = app.activeDocument.selection[0]; 

    // Position of the text end 
    var endPoint = fnText.length - 1; 

    // Add an empty footnote where the selected text is 
    var fNote = app.activeDocument.selection[0].footnotes.add(); 

    // Duplicate the selected text at the end of the empty footnote 
    fnText.duplicate(LocationOptions.AFTER, fNote.insertionPoints[-1]); 

    // Delete the old Text 
    fnText.characters.itemByRange(0, endPoint).contents = ""; 
} 
+0

스크립트 오류가 밖으로 "텍스트가 현재 위치로 이동할 수 없습니다" 세 번째 단계에서. 제 2 단계 후에는 각주가 선택 항목에 포함되어 있기 때문에 생각합니다. –

+0

InDesign CS4를 사용하고 있습니까? 그것은 나에게 같은 오류를 주었다. 그러나 나는 나를 위해 일한 다른 해결책을 발견했다. 귀하의 추측이 맞을 수도 있습니다. 각주는 특정 insertionPoint에 연결되어 있습니다. 따라서이 지점이 선택 범위 내에있는 경우 각주도 마찬가지입니다. 그러나 그들은 CS5의 행동을 당신이 기대하는 것보다 더 많이 바꾼 것으로 보입니다. – Jonas

+0

우수! 너는 천재 야. 어떻게이 모든 것을 배웠습니까? 객체 모델 뷰어에서? 샘플 스크립트를 공부하면됩니까? 고마워. –

관련 문제