2017-08-28 106 views
3

我正在處理一個腳本,它將剪貼板粘貼到每個選定的框架中。經過四周搜索,我沒有弄清楚如何將東西粘貼到框架(或多邊形)。InDesign腳本:過去到框架

我被堵在這樣的事情:

function pasteSelection(mySelection) { 
    for (var i = mySelection.length - 1; i > -1; i--) { 
     mySelection[i].contents = app.paste(); 
    } 
} 

我應該mySelection[i].contents = app.paste()是什麼?

回答

0

根據another answer I provided not long ago,這會有所幫助。對於這個片段來粘貼任何東西,你必須在你的文檔中選擇TEXT。這就是這個片段知道粘貼的地方。

var myDoc = app.activeDocument; 

if(app.documents.length != 0){ 
    if(app.selection.length == 1){ 
     try{   
      var frame1 = app.selection[0]; 
      frame1 = app.paste();//works 
      //app.pasteWithoutFormatting(frame1);;works too 
     } 
     catch(e){ 
      alert ("Exception : " + e, "Exception"); 
     } 
    } 
else{ 
    alert ("Please select text", "Selection"); 
    } 
} 
else{ 
    alert("Something wrong"); 
} 

更新以下評論: 對於這個片段我創建到我創建了2個對象InDesign文檔。一個對象是一個文本框,我在其中輸入了一堆文本,第二個項目僅僅是我繪製在文本框下面的一個多邊形。我沒有設置多邊形的內容類型,我只是畫了多邊形。爲了有效地找到我真正想要和需要的頁面項,我使用Script Labels,但使用標籤不是必需的。只要你有一種機制知道你正在處理正確的對象。

這段代碼背後的想法很簡單:

  1. Select the Source object
  2. Copy the selected object
  3. Select the Destination object
  4. Paste into the selected object

var myDoc = app.activeDocument; 
var source; 
var destination; 

for(var i = 0; i < myDoc.pageItems.length; i++) 
{ 
    if(myDoc.pageItems[i].label == "source") 
    { 
     source = myDoc.pageItems[i]; 
     app.selection = myDoc.pageItems[i]; 
     app.copy(); 
     } 
    else if(myDoc.pageItems[i].label == "destination") 
    { 
     destination = myDoc.pageItems[i]; 
     } 

    if(source !== undefined && destination !== undefined) 
    { 
     break; 
     } 
} 
app.selection = destination; 
app.pasteInto(); 
+0

使用哪個命令可以直接將我的剪貼板**插入到**多邊形中?例如。我選擇一個多邊形,運行腳本,之後我將一個文本框粘貼到該多邊形中。 – Malte

+0

@Malte,已更新 –

+0

謝謝!關鍵是我不知道的app.pasteInto()。我正在使用'app.paste()' – Malte