Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Find text and redefine font family name, style, size and leading.

Explorer ,
Jul 12, 2021 Jul 12, 2021

Copy link to clipboard

Copied

Hi Teams, For my request, I need to find a word in a paragragh and redefine the font family name, style, size and leading.

 

Ex. a sample snap attached here.

 

BalajiMurugesan_0-1626110347650.png

 

 

For this snap: Word "consectetur" font size is 30pt, and i need to find the text and redefince font family name, style, size and leading with new value. Thanks

TOPICS
Actions and scripting

Views

209

Likes

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

correct answers 1 Correct answer

Adobe Community Professional , Jul 13, 2021 Jul 13, 2021
Everything is not so simple and reliable there. In general, it is impossible to correctly change the properties of the text (depends on the text) Try this var s = activeDocument.activeLayer.textItem.contents; var x1 = s.indexOf("consectetur"); if (x1 >= 0) set_text_style(x1, "consectetur".length, mdf); function mdf(d) { try { var sz_v = d.getUnitDoubleValue(stringIDToTypeID("impliedFontSize")); var sz_t = d.getUnitDoubleType(stringIDToTypeID("impliedFontSize")...

Likes

Translate

Translate
Adobe Community Professional ,
Jul 12, 2021 Jul 12, 2021

Copy link to clipboard

Copied

Can you mark correct answer in previous thread you created, or if there is not any that satisfy your expectations, to say why? Text is overset text?

Likes

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
Explorer ,
Jul 12, 2021 Jul 12, 2021

Copy link to clipboard

Copied

Hi @Kukurykus, still that request is work in progress and will let you know as soon as possible the status. Kindly review my new request. I need to find a text and redefine character format based custom puts. Like as if font size is 30. I need to add extre 2 point and results 32 is applied in the finded text. Your help much appreciated ☺️

Likes

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
Adobe Community Professional ,
Jul 12, 2021 Jul 12, 2021

Copy link to clipboard

Copied

The best answer you can get for now from r-bin linked thread 😉

Likes

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
Adobe Community Professional ,
Jul 12, 2021 Jul 12, 2021

Copy link to clipboard

Copied

There is something similar here:

Specific character changing to Small Caps

 

Likes

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
Explorer ,
Jul 13, 2021 Jul 13, 2021

Copy link to clipboard

Copied

Hi @r-bin, Thanks a ton.

i will helpful to redefine font name.

Addtionaly i request you to, I need to find a text and redefine character format based custom inputs. Like as if font size is 30. I need to add extre 2 point and results 32 is applied in the finded text. Your help much appreciated ☺️

 

BalajiMurugesan_0-1626164779501.png

Ex: the word Consectetur font size is 30, I need to redefine the value as 32, if 50 means it need to redefine as 52.
Same as leading if leading 94 means i need to find current leading value and add 2, then redefine the new value 96 same finding words.

 

Thanks

 

Likes

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
Adobe Community Professional ,
Jul 13, 2021 Jul 13, 2021

Copy link to clipboard

Copied

Everything is not so simple and reliable there. In general, it is impossible to correctly change the properties of the text (depends on the text)

 

Try this

 

var s = activeDocument.activeLayer.textItem.contents;

var x1 = s.indexOf("consectetur");
if (x1 >= 0) set_text_style(x1, "consectetur".length, mdf); 
 

function mdf(d) 
    {
    try { 
        var sz_v = d.getUnitDoubleValue(stringIDToTypeID("impliedFontSize"));
        var sz_t = d.getUnitDoubleType(stringIDToTypeID("impliedFontSize"));
        d.putUnitDouble(stringIDToTypeID("impliedFontSize"), sz_t, sz_v+2);


        var sz_v = d.getUnitDoubleValue(stringIDToTypeID("impliedLeading"));
        var sz_t = d.getUnitDoubleType(stringIDToTypeID("impliedLeading"));
        d.putUnitDouble(stringIDToTypeID("impliedLeading"), sz_t, sz_v+2);
        }
    catch (e) { throw (e); }
    }

function set_text_style(from, len, style_modifier) 
    { 
    try { 
        // get textKey descriptor for activeLayer

        var r = new ActionReference(); 
        r.putEnumerated(stringIDToTypeID("textLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum")); 
        var textKey = executeActionGet(r).getObjectValue(stringIDToTypeID("textKey"));

        var list = textKey.getList(stringIDToTypeID("textStyleRange"));
        var new_list = new ActionList(); 

        // get styles of each char, modify if needed
        var styles = new Array();           

        var x = 0; // chars counter

        for (var i = 0; i < list.count; i++)
            {
            var d = list.getObjectValue(i);

            var x0 = d.getInteger(stringIDToTypeID("from"));
            var x1 = d.getInteger(stringIDToTypeID("to"));

            var st = d.getObjectValue(stringIDToTypeID("textStyle"));

            for (var n = 0; n < x1-x0; n++)
                {
                if (x >= from && x < from+len) // modify current style
                    {
                    var d = new ActionDescriptor(); 
                    d.fromStream(st.toStream()); // duplicate style
                    style_modifier(d);           // modify current style
                    styles.push(d);
                    }
                else
                    {
                    styles.push(st);
                    }

                ++x;
                }
            }

        styles.push(new ActionDescriptor());

        // scan styles, modify if needed, compact to range (from-to)

        var from = 0;

        for (var i = 0; i < styles.length-1; i++)
            {
            if (!styles[i].isEqual(styles[i+1]))
                {
                var d = new ActionDescriptor(); 
                d.putInteger(stringIDToTypeID("from"), from); 
                d.putInteger(stringIDToTypeID("to"), i+1); 
                d.putObject(stringIDToTypeID("textStyle"), stringIDToTypeID("textStyle"), styles[i]); 

                new_list.putObject(stringIDToTypeID("textStyleRange"), d);

                from = i+1;
                }
            }

        // put new styles to textKey descriptor

        textKey.putList(stringIDToTypeID("textStyleRange"), new_list); 

        // set modified textKey back to textLayer

        var d = new ActionDescriptor(); 
        var r = new ActionReference(); 
        r.putEnumerated(stringIDToTypeID("textLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum")); 
        d.putReference(stringIDToTypeID("null"), r); 
        d.putObject(stringIDToTypeID("to"), stringIDToTypeID("textLayer"), textKey); 

        executeAction(stringIDToTypeID("set"), d, DialogModes.NO); 
        } 

    catch (e) { alert(e); }  
    } 

Likes

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
Explorer ,
Jul 18, 2021 Jul 18, 2021

Copy link to clipboard

Copied

LATEST

Hi @r-bin, I requested you to kindly review my next queries, and help me for this if possible.

Find postscript font upto textstylerange and replace a new postscript name based on Input data.

 

Thanks

Likes

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
Adobe Community Professional ,
Jul 13, 2021 Jul 13, 2021

Copy link to clipboard

Copied

I have a sample script on my Dropbox that does this. You WILL need to edit the script with your parameters.
Adobe Scripts

Look for Photoshop Scripts->Update text layers

You can search for specific text, replace it, and set formatting.

Likes

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
Explorer ,
Jul 17, 2021 Jul 17, 2021

Copy link to clipboard

Copied

Hi @Lumigraphics, Thanks for your set of scripts. i will look into this and let you as soon as possible.

Likes

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