Skip to main content
Balaji Murugesan
Known Participant
May 19, 2021
Answered

Text is overset text?

  • May 19, 2021
  • 1 reply
  • 2876 views

Hi Team,

 

Kindly let me know how to find text overset available in psd file using javascript/script listener.

 

Thanks

Correct answer c.pfaffenbichler

c.pfaffenbichler

I practically don't work with text. I know very little about it. You can try this way.

var y1 = activeDocument.activeLayer.bounds[3].value;
var h = activeDocument.activeLayer.textItem.height;

activeDocument.activeLayer.textItem.height = 2*h;

var y2 = activeDocument.activeLayer.bounds[3].value;

activeDocument.activeLayer.textItem.height = h;

alert(y2-y1)

 

If the result y2-y1 is zero, then with a high probability we can say that all the text is visible.


Thanks! 

 

I tried to follow up on the point text work-around. 

// check if type layers in active document have overset text;
// 2021, use it at your own risk;
if (app.documents.length > 0) {
    var theCheck = checkForOversetText ();
    alert ("layers with index "+theCheck.join(", ")+" contain overset text")
};
////// check for overset texts //////
function checkForOversetText () {
    var ref = new ActionReference();
    ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
    var applicationDesc = executeActionGet(ref);
    var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
    var theArray = new Array;
// work through layers;
    for (var m = theNumber; m >= 0; m--) {
        try {
////////////////////////////////////
var someValues = someTextProperties(m);
if (someValues != false){
if (someValues[0] == "box"){
// convert to point type;
var desc01 = new ActionDescriptor();
var ref5 = new ActionReference();
ref5.putProperty( stringIDToTypeID( "property" ), stringIDToTypeID( "char" ) );
ref5.putIndex( stringIDToTypeID( "textLayer" ), m );
desc01.putReference( stringIDToTypeID( "null" ), ref5 );
desc01.putEnumerated( stringIDToTypeID( "to" ), stringIDToTypeID( "char" ), stringIDToTypeID( "paint" ) );
executeAction( stringIDToTypeID( "set" ), desc01, DialogModes.NO );
var otherValues = someTextProperties(m);
// undo;
activeDocument.activeHistoryState = activeDocument.historyStates[activeDocument.historyStates.length - 2];
// compare;
    var theCheck = true;
    var theNumber1 = 0;
    var theNumber2 = 0;
    while (theCheck == true && theNumber1 != someValues[1].length) {
        var value1 = someValues[1][theNumber1];
        var value2 = otherValues[1][theNumber2];
        if (value1 != value2) {
            switch (value2) {
                case "\r":
                    theNumber1++;
                    theNumber2++;
                    break;
                case "-":
                    theNumber2++;
                    theNumber2++;
                    break;
                default:
                    theCheck = false;
                    break;
                };
        } else {
        theNumber1++;
        theNumber2++
        }
    };
if (theCheck == false) {theArray.push(m)}
else {};
}
};
////////////////////////////////////
    }
    catch (e) {};
    };
// select layers;
if (theArray.length > 0) {
    selectLayerByIndex(theArray[0],false);
    for (var x = 1; x < theArray.length; x++) {
    selectLayerByIndex(theArray[x],true)
    }
};
// return results;
return theArray
};
////// check something //////
function someTextProperties (theIndex) {
    try {
        var ref = new ActionReference();
        ref.putProperty(stringIDToTypeID( "property" ), stringIDToTypeID('textKey'));
        ref.putIndex ( charIDToTypeID("Lyr "), theIndex);
        var layerDesc = executeActionGet(ref);
        var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));
        var theText = textDesc.getString(stringIDToTypeID('textKey'));
        var textShape = textDesc.getList(stringIDToTypeID('textShape'));
        var paragraph = typeIDToStringID(textShape.getObjectValue(0).getEnumerationValue(stringIDToTypeID('char')));
        return [paragraph, theText]
    } catch (e) {return false}
};
// by mike hale, via paul riggott;
function selectLayerByIndex(index,add){ 
    add = undefined ? add = false:add 
    var ref = new ActionReference();
        ref.putIndex(charIDToTypeID("Lyr "), index);
        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); 
    }
    };

 

1 reply

c.pfaffenbichler
Community Expert
May 20, 2021

Please elaborate. 

Balaji Murugesan
Known Participant
May 20, 2021

Hi,

Kindly Review below snaps.

 



Some texts are hidden under the text item.

i need to write to automation scripts thats helps to shown overset documents names.

 

Thanks

c.pfaffenbichler
Community Expert
May 20, 2021

Thanks.

 

I seem to recall past discussion/s on the issue though I couldn’t find the thread/s.

 

If you cannot identify a property in the AM code checking the text, then converting to Point Type and checking if the text is unchanged (and undoing the conversion, naturally) would provide a work-around.

 

 

The Strings of texts with more than one line cannot be identical because the line-breaks and the hyphens in the Point Text are letters, too, but by comparing letter for letter one can »filter« them out and determine if overset text exists.

One could then do that with all type layers in a document.

 

@Kukurykus , @r-bin , @jazz-y , please forgive the intrusion but at current you are the ones whose names come to my mind easily when it comes to Photoshop Scripting advice on this Forum; do any of you have a better idea or an immediate way of determining overset text in a Type Layer?