Skip to main content
Participant
September 26, 2018
Question

Script to Change Leading Based on Text Size Returns Wrong Value

  • September 26, 2018
  • 0 replies
  • 722 views

Hi all. I'm writing a javascript that will set the leading to 93% of the text size. Pretty simple and my first script worked great on about half my ads. However, in any artboard where the text has been resized via transform, the text size value from textItem.size is the original value before the transform, not the actual current text size.

Is there any way to either retrieve the currently displayed text size (preferred) or the amount of transform that has been applied to the text?

Thank you!

function changeLeading()
{
    //set a variable to point to the layer we want to change
    var artLayerRef = docRef.layerSets.artLayers.Headline;

    //set a variable to the current layers text size
    var textSize = artLayerRef.textItem.size;

    //Break point for debugging
    alert("Font Size = " + textSize);

    //Math to calculate correct leading based on text size
    var lineSpace = artLayerRef.textItem.size * 0.93;

    //Break point for debugging
    //alert("Leading to be set to " + lineSpace);

    //Change the leading to the new value
    artLayerRef.textItem.leading=lineSpace;
}

This topic has been closed for replies.