根據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
,但使用標籤不是必需的。只要你有一種機制知道你正在處理正確的對象。
這段代碼背後的想法很簡單:
Select the Source object
Copy the selected object
Select the Destination object
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();
使用哪個命令可以直接將我的剪貼板**插入到**多邊形中?例如。我選擇一個多邊形,運行腳本,之後我將一個文本框粘貼到該多邊形中。 – Malte
@Malte,已更新 –
謝謝!關鍵是我不知道的app.pasteInto()。我正在使用'app.paste()' – Malte