Copy link to clipboard
Copied
I am a catalog production artist. I have been working with a JSX script which fetches and places INDD snippets from a folder based the file name. I would like to streamline my process by forgoing the Snippets, and simply copy the required text frames from one INDD document to another, identifying the required text frames by searching on the Script Label. I have this bit of code that works to select a specific text frame. However, once it finds the target, it doesn't do anything with it;
do
{
if (app.documents.length == 0)
{
break;
}
var document = app.activeDocument;
if (! (document instanceof Document))
{
break;
}
var currentItem = null;
if (app.selection.length > 0)
{
currentItem = app.selection[0];
}
var undoneItems = [];
for (var idx = 0; idx < document.allPageItems.length; idx++)
{
var pageItem = document.allPageItems[idx];
if (pageItem.label == "11010001")
{
undoneItems.push(pageItem);
}
}
if (undoneItems.length <= 0)
{
break;
}
var nextItemIdx = 0;
if (currentItem != null)
{
var currentItemIdx = -1;
var searchItemIdx = 0;
while (currentItemIdx == -1 && searchItemIdx < undoneItems.length)
{
if (undoneItems[searchItemIdx] == currentItem)
{
currentItemIdx = searchItemIdx;
}
searchItemIdx++;
}
if (currentItemIdx >= 0)
{
nextItemIdx = currentItemIdx + 1;
if (nextItemIdx >= undoneItems.length)
{
nextItemIdx = 0;
}
}
}
app.select(undoneItems[nextItemIdx]);
}
while (false);
However, the Script Label is hard coded in the script which you can see in the highlighted line above. What I want is to be able to do is feed a text document of 8 digit numbers, have the script walk though the entire INDD source file, and copy the found items from the text file into an empty INDD target file. An extra bonus would be if the script could return a report of items it did not locate when completed.
Try this code, this might help you...
...var myFile = File(".../Desktop/Test/TestFile.txt");
myFile.open("r");
myLine = myFile.read();
myFile.close();
var lines = myLine.split(/\r?\n/);
var allLabels = [];
for(var i = 0; i < lines.length; i++){
allLabels.push(lines.toString());
}
var myDoc = app.documents[0];
var pages = myDoc.pages;
for(var p = 0; p < pages.length; p++){
var pageItems = pages.allPageItems;
for(var pt = 0; pt < pageItems.length; pt++){
if(pageItems[pt].label != ""){
Copy link to clipboard
Copied
The requirement is not clear. Answer the following questions
And the above steps are repeated till all the numbers in text file are processed.
Correct if something is wrong or something is missing.
-Manan
Copy link to clipboard
Copied
Yes, you have the process correct. Ideally, these found items copied into a document which is opened by the user.
Copy link to clipboard
Copied
Try this code, this might help you...
var myFile = File(".../Desktop/Test/TestFile.txt");
myFile.open("r");
myLine = myFile.read();
myFile.close();
var lines = myLine.split(/\r?\n/);
var allLabels = [];
for(var i = 0; i < lines.length; i++){
allLabels.push(lines.toString());
}
var myDoc = app.documents[0];
var pages = myDoc.pages;
for(var p = 0; p < pages.length; p++){
var pageItems = pages.allPageItems;
for(var pt = 0; pt < pageItems.length; pt++){
if(pageItems[pt].label != ""){
var found = match(pageItems[pt], allLabels);
if(found){
/// Do your stuff here whether you want to copy or whatever you want to do-----
}
}
}
}
////////////////////////////////////////////////
function match(myItem, myArray){
for(var q = 0; q < myArray.length; q++){
if(myArray
.toString() == myItem.label.toString()){return true;
}
}
return false;
}
Copy link to clipboard
Copied
@yDvs92328: I cannot get past line 13. I get an error that says, "Object does not support the property or method 'allPageItems." BTW: I am working INDD CC 2019 for Mac if it makes a difference.
Copy link to clipboard
Copied
It should be:
var pageItems = pages.allPageItems;
Variable pages holds the pages collection of the document.
Regards,
Uwe
Copy link to clipboard
Copied
Sorry Bro,
That was a silly mistake,
Just change that line 13
var pageItems = pages[0].allPageItems;
Copy link to clipboard
Copied
Why [0] ?
Wouldn't you like to loop through all items of your pages collection?
Regards,
Uwe
Copy link to clipboard
Copied
I meant to use index of pages there.
Copy link to clipboard
Copied
Have a look at this snippet-placer tool
http://www.indesignscript.de/skript-detail/detail/News/snippetplacer/
Thx Stefan
Copy link to clipboard
Copied
Sorry Stephan, that tool is in German and Ich spreche kein deutsch. Thanks though.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now