Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Find items via script label

Explorer ,
Jan 10, 2019 Jan 10, 2019

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.

TOPICS
Scripting
3.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Jan 10, 2019 Jan 10, 2019

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 != ""){

       

...
Translate
Community Expert ,
Jan 10, 2019 Jan 10, 2019

The requirement is not clear. Answer the following questions

  • The input would be a text file with each line of eight digit numbers? Like
    • 12345678
    • 23456789
  • The script will parse this text file, pick up each number and find all the frames in the activedocument in InDesign with the label equal to this number
  • Copy these frames over to a new document? Will this document be open or do you want this document to be opened, frames copied over and then the document saved and closed.

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 14, 2019 Jan 14, 2019

Yes, you have the process correct. Ideally, these found items copied into a document which is opened by the user.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 10, 2019 Jan 10, 2019

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;

    }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 14, 2019 Jan 14, 2019

@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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2019 Jan 14, 2019

It should be:

var pageItems = pages

.allPageItems;

Variable pages holds the pages collection of the document.

Regards,
Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 15, 2019 Jan 15, 2019

Sorry Bro,

That was a silly mistake,

Just change that line 13

var pageItems = pages[0].allPageItems;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 15, 2019 Jan 15, 2019

Why [0] ?

Wouldn't you like to loop through all items of your pages collection?

Regards,
Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 15, 2019 Jan 15, 2019
LATEST

I meant to use index of pages there.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 11, 2019 Jan 11, 2019

Have a look at this snippet-placer tool

http://www.indesignscript.de/skript-detail/detail/News/snippetplacer/

Thx Stefan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 14, 2019 Jan 14, 2019

Sorry Stephan, that tool is in German and Ich spreche kein deutsch. Thanks though.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines