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

Overset text from hidden layers included in search results despite includeHiddenLayers being set to false

Community Beginner ,
May 17, 2018 May 17, 2018

Copy link to clipboard

Copied

When setting the includeHiddenLayers property to false and performing a search on a document, it seems you will always get results from overset text, no matter whether the overflowing parent textframe is on a hidden layer.

Below you will find a piece of test code.

1. Create two layers in a new document

2. Put a textframe on one of the layers, and write 12-1234 into it (that will be a match for my regex below).

3. Put some text or line breaks before the digits, so that the digits get out of sight (overset, indicated by plus sign).

Run the code below from the Extendscript Toolkit (or change the $.writeln to an alert).

var activeDocument = app.activeDocument;

// First hide all layers, to be able to handle them one by one

activeDocument.layers.everyItem().visible = false;

// Loop through the layers

for (var iLayer=0; iLayer<= activeDocument.layers.length-1; iLayer++){

   

    var theLayerItem = activeDocument.layers[iLayer];

   

    // Show the layer that is to be processed

    activeDocument.layers.itemByName(theLayerItem.name).visible = true;

   

    var findings = grepFind (app.activeDocument, '\\d\\d-\\d+', false);

    var msg = 'Items found on layer "' + theLayerItem.name + '": '+  findings.length ;

    if (findings[0].parent.insertionPoints[0].parentTextFrames[0].itemLayer.name != theLayerItem.name){

       msg += ' but the text actually belongs to layer ' + findings[0].parent.insertionPoints[0].parentTextFrames[0].itemLayer.name;

    }

    $.writeln(msg);

   

    // hide the current layer when we are done with it

    activeDocument.layers.itemByName(theLayerItem.name).visible = false;

}

// Now when we are dont, show all layers again

activeDocument.layers.everyItem().visible = true;

function grepFind(objToSearch, grepPattern, includeHiddenLayers){

    app.findGrepPreferences = app.changeGrepPreferences = null; // reset the find preferences

    app.findGrepPreferences.findWhat = grepPattern;

    app.findChangeGrepOptions.includeHiddenLayers = includeHiddenLayers;

    return objToSearch.findGrep();

}

In the console window I get the following log:

Items found on layer "Layer 1": 1

Items found on layer "Layer 2": 1 but the text actually belongs to layer Layer 1

Meaning that the text "12-1234" was found twice. One time for each layer.

The same goes for normal text search as well – nothing grep specific, that is.

Do I really have to check each item in the result, or is there another way to prevent overset text from hidden layers to be included in the search result like this?

--- Edit: adding a piece about the user interface
The user interface seems to have the same (in my opinion unintuitive) way of working. Overset text on a hidden layer, is found no matter whether "Include Hidden Layers and Hidden Objects" is selected.

The message was edited by: Andreas Jansson. Adding a couple of lines in the test code, and a piece about the InDesign UI search working in the same way.

TOPICS
Scripting

Views

463

Translate

Translate

Report

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 Beginner ,
May 17, 2018 May 17, 2018

Copy link to clipboard

Copied

LATEST

My best guess is that this is "by design"... but not a very good design...

My workaround will be something like this:

// Limit the search to a certain layer.

function filterFindingsByLayer(findings, layer){

    var filteredFindings = new Array;

    for (var i=0; i<= findings.length-1; i++){

        // Check that all properties are defined before using them

        if (findings.parent && findings.parent.insertionPoints && findings.parent.insertionPoints[0].parentTextFrames){

            if (findings.parent.insertionPoints[0].parentTextFrames[0].itemLayer.name === layer.name){

                filteredFindings.push (findings);

            }

        }

    }

    return filteredFindings;

}


// Call the function above with the result from a search

var findings = filterFindingsByLayer(grepFind (app.activeDocument, '\\d\\d-\\d+', false), theLayerItem);

Feel free to comment.

Votes

Translate

Translate

Report

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