Skip to main content
Inspiring
April 3, 2024
Question

find a word or number and zoom to find in photoshop ?

  • April 3, 2024
  • 9 replies
  • 1077 views

Hi,

CS6

I have many layers, some of which are text tool made.

I wish to search for e.g the number 91 and then zoom to it as the file is massive and very tall.

Its a montage of ladder types. each ladder has a Type number such as Type 43 written over it as a text layer and grouped to it.

Searching for such numbers by eye takes forever, as they are placed to suit ladder design and not in numerical order.

So once found how can I zoom to the find ?

 

Cheers

 

Merlin3

This topic has been closed for replies.

9 replies

c.pfaffenbichler
Community Expert
Community Expert
April 4, 2024

Does Photoshop CS6 feature View > Fit Layer(s) on Screen? 

Merlin3Author
Inspiring
April 4, 2024

Hi,

alas...no,

I will try and do a test file, the real one is 3.1Gb

Merlin3

Legend
April 5, 2024

That's a really large file, what computer do you have? I'm guessing an older one since you are on CS6?

Jeff Arola
Community Expert
Community Expert
April 4, 2024

Did you try the built-in Layer Search as explained in this viseo?

https://www.youtube.com/watch?v=Zi327Jyb4Ws

 

Legend
April 4, 2024

Does Layer Search include finding text contents? I'd love to use it if it did, but I haven't found that feature.

c.pfaffenbichler
Community Expert
Community Expert
April 4, 2024

Edit: The OP claimed that the text and the name of the Layer would be identical so the name-search should suffice. 

c.pfaffenbichler
Community Expert
Community Expert
April 4, 2024

Come to think of it: How should multiple finds be handled (if the number appears more than once in an image)? 

 

Edit: Another Script to find text in Type Layers; it just selects all the Type Layers that contain the String. 

// select type layers containing certain text;
// 2022, use it at your own risk;
if (app.documents.length > 0) {
selectTypeLayerWithText("tempor")
};
////////////////////////////////////
function selectTypeLayerWithText (theString) {
var theCheck = false;
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true && layerDesc.hasKey(stringIDToTypeID("textKey")) == true) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));
var theText = textDesc.getString(stringIDToTypeID('textKey'));
// compare text;
if (theText.match(theString) != null) {
    selectLayerByID(theID,theCheck);
    theCheck = true;
    theLayers.push([theName, theID, theText])
};
};
}
catch (e) {};
};
if (theLayers.length == 0) {
    alert ("no matching layer"); 
    return
} else {return theLayers}
};
// based on code by mike hale, via paul riggott;
function selectLayerByID(id,add){ 
add = undefined ? add = false:add 
var ref = new ActionReference();
    ref.putIdentifier(charIDToTypeID("Lyr "), id);
    var desc = new ActionDescriptor();
    desc.putReference(charIDToTypeID("null"), ref );
       if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
      desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
   try{
    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}catch(e){
alert(e.message); 
}
};

 

Merlin3Author
Inspiring
April 4, 2024

Hi,

run that script, error 8800 , version of photoshop etc , may not work etc.

 

and I have only one of each Type Number, I just abutt images with same Type number of object before labelling.

 

Cheers

Merlin3

c.pfaffenbichler
Community Expert
Community Expert
April 4, 2024

As @Lumigraphics mentioned more information is needed. 

I also don’t have access to Photoshop CS6 at my work.

And I suspect the same may apply to many of the other regulars, so it may be impossible to get a solution for your exact problem. 

 

Again: Please provide a sample file. 

c.pfaffenbichler
Community Expert
Community Expert
April 4, 2024

I am not sure a Photoshop version like CS6 will run the Script, but in principle one can determine the position of an image in the window (thanks to @r-bin ); with the Script below the selected Layer should be centered. (see screenshots)

// move the center of the window to selected layer;
// 2024, use it at your own risk;
if (app.documents.length > 0) {
var layerBounds = activeDocument.activeLayer.bounds;
// pixels;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// get window values;
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("viewInfo"));    
r.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));    
var bounds = executeActionGet(r).getObjectValue(stringIDToTypeID("viewInfo")).getObjectValue(stringIDToTypeID("activeView")).getObjectValue(stringIDToTypeID("globalBounds"));
var theLeft = bounds.getUnitDoubleValue(stringIDToTypeID("left"));
var theTop = bounds.getUnitDoubleValue(stringIDToTypeID("top"));
var theRight = bounds.getUnitDoubleValue(stringIDToTypeID("right"));
var theBottom = bounds.getUnitDoubleValue(stringIDToTypeID("bottom"));
var windowW = theRight - theLeft -16;
var windowH = theBottom - theTop - 16;
// get zoom;
var theZoom = getActiveDocumentZoom();
// set position:
set_doc_position((Number(layerBounds[0])+(Number(layerBounds[2])-Number(layerBounds[0]))/2)*(-1)*theZoom/100+windowW/2, (Number(layerBounds[1])+(Number(layerBounds[3])-Number(layerBounds[1]))/2)*(-1)*theZoom/100+windowH/2);
//set_doc_position(theX*(-1)*theZoom/100+windowW/2, theY*(-1)*theZoom/100+windowH/2);
app.preferences.rulerUnits = originalRulerUnits;
//}
};
////////////////////////////////////
//  by r-bin;
function set_doc_position(x, y)  
{  
try {  
    var r = new ActionReference();    
    r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("viewInfo"));    
    r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));    
    var bounds = executeActionGet(r).getObjectValue(stringIDToTypeID("viewInfo")).getObjectValue(stringIDToTypeID("activeView")).getObjectValue(stringIDToTypeID("globalBounds"));          
    var b = new Array();
    b[0] = bounds.getUnitDoubleValue(stringIDToTypeID("left"));          
    b[1] = bounds.getUnitDoubleValue(stringIDToTypeID("top"));  
    b[2] = bounds.getUnitDoubleValue(stringIDToTypeID("right"));  
    b[3] = bounds.getUnitDoubleValue(stringIDToTypeID("bottom"));  

    var dx = 8; // what is it?  
    var dy = 8; // what is it?  

    x = (b[2]-b[0])/2 - x - dx;  
    y = (b[3]-b[1])/2 - y - dy;  

    var d = new ActionDescriptor();    
    var r = new ActionReference();    
    r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("center"));    
    r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));    
    d.putReference(stringIDToTypeID("null"), r);    

    var d1 = new ActionDescriptor();    

    d1.putUnitDouble(stringIDToTypeID("horizontal"), stringIDToTypeID("distanceUnit"), x);  
    d1.putUnitDouble(stringIDToTypeID("vertical"),   stringIDToTypeID("distanceUnit"), y);  

    d.putObject(stringIDToTypeID("to"), stringIDToTypeID("center"), d1);    
    executeAction(stringIDToTypeID("set"), d, DialogModes.NO);    
    }  
catch (e) { throw(e); }  
};
// by mike hale;
function getActiveDocumentZoom(){
   var ref;
   ref = new ActionReference();
   ref.putProperty( charIDToTypeID( "Prpr" ),charIDToTypeID('Zm  '));
   ref.putEnumerated(charIDToTypeID('Dcmn'), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
   return (executeActionGet(ref).getUnitDoubleValue (charIDToTypeID('Zm  ')))*100;
};

 

c.pfaffenbichler
Community Expert
Community Expert
April 4, 2024

Please provide a sample file. 

Stephen Marsh
Community Expert
Community Expert
April 3, 2024

CS6 is so old that I can't remember if it has a menu item under View > Fit Layer(s) on Screen ?

 

Does the layer name match the text content?

Merlin3Author
Inspiring
April 4, 2024

Hi,

yes, when I type out the label for the photo that text is then also the label name.

Cheers

DBenz

Legend
April 3, 2024

This is a basic Photoshop script to find text in layers. If the search term if found, the layer is selected and the script stops.

You'll have to figure out zooming in on the text and add it from here.

 

/*
Utility Pack Scripts created by David M. Converse ©2018-24

This script finds text in open Photoshop documents

Last modifed 4/3/2024

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#target photoshop

findText();

function findText(){
    if(documents.length > 0){
        var searchTerm = '';
        var found = false;
        var docRef = activeDocument;
        try{
            searchTerm = Window.prompt('Enter the text to search for');
            if(searchTerm == null){
                return;
                }
            else{
                searchTerm = searchTerm.toLowerCase();
                for(var i = 0; i < docRef.artLayers.length; i++){
                    var LayerRef = docRef.artLayers[i];
                    if(LayerRef.kind == LayerKind.TEXT){
                        var TextRef = LayerRef.textItem;
                        var layerText = TextRef.contents;
                        layerText = layerText.toLowerCase();
                        if(layerText.search(searchTerm) != -1){
                            found = true;
                            docRef.activeLayer = LayerRef;
                            return;
                            }
                        }
                    }
                if(found == false){
                    Window.alert(searchTerm + ' not found');
                    return;
                    }
                }
            }
        catch(e){
            Window.alert(e + e.line);
            }
        }
    }
Merlin3Author
Inspiring
April 3, 2024

Hi, Thanks for the script, I googled how to use a script, saved it as a .jsx, file> scripts browse to script ran it, entered 39 to search for, and waited, GPU fan increased, waited 2 mins. nothing happened, photoshop had frozen, so end task.

relaunch Pshop.

try for a word, same problem, third time try *handrail* get syntax error,

so unable to get it to work.

 

DBenz

Legend
April 4, 2024

I do not have CS6 to test with so I can't promise that the script works. But the basics should be the same, that's an example of what you'd need to write.

Jeff Arola
Community Expert
Community Expert
April 3, 2024

Photoshop CS6 has Layer Search:

https://www.youtube.com/watch?v=Zi327Jyb4Ws

Legend
April 3, 2024

I don't think textitem contents can be searched with this? Its mostly layer attributes such as blend modes and visibility.

Legend
April 3, 2024

This would require a custom script to search text layers.