Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

Replace text in text layers

$
0
0

I found a function from c.pfaffenbichler here on the forum, which will search/replace text. The script works great if you have a flat document, but as soon as you create a group the script won't work anymore.

 

Here's the function:

function replaceText (searchText, replaceWith)
{    var actionDes1 = new ActionDescriptor();    var actionRef = new ActionReference();    actionRef.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID("replace") );    actionRef.putEnumerated( charIDToTypeID( "TxLr" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Al  " ) );    actionDes1.putReference( charIDToTypeID( "null" ), actionRef );    var actionDes2 = new ActionDescriptor();    actionDes2.putString( stringIDToTypeID( "find" ), searchText );    actionDes2.putString( stringIDToTypeID("replace"), replaceWith );    actionDes2.putBoolean( stringIDToTypeID( "checkAll" ), false );    actionDes2.putBoolean( charIDToTypeID( "Fwd " ), true );    actionDes2.putBoolean( stringIDToTypeID( "caseSensitive" ), false );    actionDes2.putBoolean( stringIDToTypeID( "wholeWord" ), false );    actionDes2.putBoolean( stringIDToTypeID( "ignoreAccents" ), true );    actionDes1.putObject( charIDToTypeID( "Usng" ), stringIDToTypeID( "findReplace" ), actionDes2 );    executeAction( stringIDToTypeID("replace"), actionDes1, DialogModes.NO );
};
replaceText ("test", "replaceWithStuff")

 

Here's the error I get:

---------------------------
Error
---------------------------
Error 8800: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- The object "in contents of all text layer" is not currently available.
Line: 21
->      executeAction( stringIDToTypeID("replace"), actionDes1, DialogModes.NO );
---------------------------
OK  
---------------------------

 

Does anyone know how to work around this problem? I've tried a try/catch, the only thing that does is to suppress the error, but it won't replace the text :/


Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>