Skip to main content
hiro-e
Participant
February 5, 2024
Question

any idea for areaText vertical align via script

  • February 5, 2024
  • 1 reply
  • 331 views

 

var labelPath = grp.pathItems.rectangle(10, 0, 100, 20);
var labelText = grp.textFrames.areaText(labelPath);
labelText.contents = "label text";
labelText.name = "label";

 

I want the text to appear in the same place even when I change the font.
Does anyone know how to achieve this while centering text vertically on a path?
This topic has been closed for replies.

1 reply

CarlosCanto
Community Expert
Community Expert
February 5, 2024
RobOctopus
Inspiring
February 5, 2024

to add to this, here is the function I have been using. allows input for changing to whichever type of alignment. so you can do

AlignAreaText(app.activeDocument.textFrames[0], 1) for center
AlignAreaText(app.activeDocument.textFrames[0], 2) for bottom
etc

 

/*
Align Area Text Function
aligns an area frame based on an input value, 0=Top, 1=Center, 2=Bottom, 3=Justify

other action string information
The first name is the set name, in a hex based code, first number is number of characters to decode and the second string is the name converted to hex
the second name below actioncount and action, is the action name, same numbers apply, first is character length and second is name converted to hex
*/
function AlignAreaText(TextFrameToAlign, AlignNumber) {
    var ActionString = [
    '/version 3',
    '/name [ 12',
        '416c69676e54657874536574',
    ']',
    '/isOpen 1',
    '/actionCount 1',
    '/action-1 {',
        '/name [ 9',
            '416c69676e54657874',
        ']',
        '/keyIndex 0',
        '/colorIndex 0',
        '/isOpen 1',
        '/eventCount 1',
        '/event-1 {',
            '/useRulersIn1stQuadrant 0',
            '/internalName (adobe_frameAlignment)',
            '/localizedName [ 24',
                '417265612054657874204672616d65416c69676e6d656e74',
            ']',
            '/isOpen 0',
            '/isOn 1',
            '/hasDialog 0',
            '/parameterCount 1',
            '/parameter-1 {',
                '/key 1717660782',
                '/showInPalette 4294967295',
                '/type (integer)',
                '/value ' + AlignNumber,
            '}',
        '}',
    '}'].join("\n")
    var f = File(Folder.desktop+"/VerticalTextAlign.aia");
    f.open('w');
    try {
        f.write(ActionString);
    } catch (e) {/*alert(e.message)*/}
    f.close();
    app.executeMenuCommand("deselectall")
    TextFrameToAlign.selected = true;
    app.loadAction(f);
    app.doScript('AlignText', 'AlignTextSet');
    try {
        app.unloadAction('AlignTextSet', '');
    } catch (e) {/*alert(e.message)*/}
    f.remove();
}