• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Creating different alignment

Community Beginner ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

How can we set  a text frame contents to vertical alignment center using script?

TOPICS
Scripting

Views

372

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

Community Expert , Aug 13, 2022 Aug 13, 2022

Thanks @Kurt Gold you have hit the nail on the head!

 

@SA8888, here is a script that incorporates Kurt's action. Give it a try. I found the technique of saving the action file posted to the forum by @Charu Rajput. Thanks Charu!

- Mark

 

/**
 * Center text in selected text frame vertically.
 * @discussion https://community.adobe.com/t5/illustrator-discussions/creating-different-alignment/m-p/13131693
 */

// selection should be a text frame
centerSelectionVertically();



/**
 * Create and execu
...

Votes

Translate

Translate
Adobe
Adobe Employee ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Hello @SA8888,

 

Thanks for reaching out. I would request you check the steps shared in this tutorial and check if it helps: https://www.youtube.com/watch?v=YgCD5tCftDM.

 

Looking forward to your response.

 

Thanks,

Anubhav

Votes

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
Community Beginner ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Hi, @Anubhav Majumder the above video didn't help what I needed. I want to align text to the centre of the frame using script. 

Votes

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
Community Beginner ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

SA8888_2-1660325990601.png

I want to align the textframe contents the same as above using a script.

Votes

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
Community Expert ,
Aug 13, 2022 Aug 13, 2022

Copy link to clipboard

Copied

Hi @SA8888, I looked into it and unfortunately the vertical alignment setting is not exposed via the scripting API.

 

As a poor substitute, you could try something like this script, which vertically centers the text simply by moving the whole textFrame up or down. Try it out to see what I mean.

- Mark

 

/**
 * @author m1b
 */
var doc = app.activeDocument,
    item = doc.selection[0],
    dup = item.duplicate().createOutline(),
    c1 = centerOfBounds(item.geometricBounds),
    c2 = centerOfBounds(dup.geometricBounds),
    d = differenceBetweenPoints(c1, c2);

dup.remove();
item.translate(0, d[1]);


function centerOfBounds(bounds) {

    var l = bounds[0],
        t = bounds[1],
        r = bounds[2],
        b = bounds[3],
        x = l + ((r - l) / 2),
        y = t + ((b - t) / 2);

    return [x, y];

};


function differenceBetweenPoints(p1, p2) {

    return [-(p2[0] - p1[0]), -(p2[1] - p1[1])];

};

 

Here are screenshots showing what it does. The black keyline around it is just for visual reference.

Screen Shot 2022-08-13 at 22.15.21.pngScreen Shot 2022-08-13 at 22.15.12.pngScreen Shot 2022-08-13 at 22.15.31.pngScreen Shot 2022-08-13 at 22.17.51.png

Votes

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
Community Beginner ,
Aug 13, 2022 Aug 13, 2022

Copy link to clipboard

Copied

Hi, @m1b thankyou for the script. I'm trying to place the contents vertically aligned inside a text frame, not on the whole page.

Like the screenshot below, I have used AreaType Option --> align vertical --> center. I wanted to try this same using the script

SA8888_0-1660398263148.png

 

 

 

Votes

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
Community Expert ,
Aug 13, 2022 Aug 13, 2022

Copy link to clipboard

Copied

Running this action with a script should work.

 

Align Type vertically centred

 

Or just use the action without a script.

 

Votes

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
Community Expert ,
Aug 13, 2022 Aug 13, 2022

Copy link to clipboard

Copied

Thanks @Kurt Gold you have hit the nail on the head!

 

@SA8888, here is a script that incorporates Kurt's action. Give it a try. I found the technique of saving the action file posted to the forum by @Charu Rajput. Thanks Charu!

- Mark

 

/**
 * Center text in selected text frame vertically.
 * @discussion https://community.adobe.com/t5/illustrator-discussions/creating-different-alignment/m-p/13131693
 */

// selection should be a text frame
centerSelectionVertically();



/**
 * Create and execute "Center vertically"
 * action on the selection.
 * @author KurtGold created this action.
 */
function centerSelectionVertically() {

    var actionString = "/version 3\n" +
        "/name [ 29\n" +
        "	616c69676e5f747970655f766572746963616c6c795f63656e74726564\n" +
        "]\n" +
        "/isOpen 1\n" +
        "/actionCount 1\n" +
        "/action-1 {\n" +
        "	/name [ 14\n" +
        "		766572746963616c5f616c69676e\n" +
        "	]\n" +
        "	/keyIndex 0\n" +
        "	/colorIndex 0\n" +
        "	/isOpen 1\n" +
        "	/eventCount 1\n" +
        "	/event-1 {\n" +
        "		/useRulersIn1stQuadrant 0\n" +
        "		/internalName (adobe_SLOAreaTextDialog)\n" +
        "		/localizedName [ 20\n" +
        "			466cc3a46368656e746578746f7074696f6e656e\n" +
        "		]\n" +
        "		/isOpen 1\n" +
        "		/isOn 1\n" +
        "		/hasDialog 0\n" +
        "		/parameterCount 3\n" +
        "		/parameter-1 {\n" +
        "			/key 1952543846\n" +
        "			/showInPalette 4294967295\n" +
        "			/type (integer)\n" +
        "			/value 1\n" +
        "		}\n" +
        "		/parameter-2 {\n" +
        "			/key 1952539754\n" +
        "			/showInPalette 4294967295\n" +
        "			/type (integer)\n" +
        "			/value 2\n" +
        "		}\n" +
        "		/parameter-3 {\n" +
        "			/key 1952541806\n" +
        "			/showInPalette 4294967295\n" +
        "			/type (integer)\n" +
        "			/value 1\n" +
        "		}\n" +
        "	}\n" +
        "}\n" +
        "";

    doActionFromString("vertical_align", "align_type_vertically_centred", actionString)

};



/**
 * Create and execute an action using
 * the parameters supplied. The action
 * file will be removed afterwards.
 * @author Charu Rajput
 * @discussion https://community.adobe.com/t5/illustrator-discussions/quot-duplicate-layer-quot-command-in-script/m-p/13131761
 * @param {TextFrame} frame - an Illustrator TextFrame.
 */
function doActionFromString(name, setName, str) {

    var tmp = File(Folder.temp + '/' + setName + '.aia');
    tmp.open('w');
    tmp.write(str);
    tmp.close();
    app.loadAction(tmp);
    app.doScript(name, setName, false);
    app.unloadAction(setName, '');
    tmp.remove();

};

 

Votes

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
Community Beginner ,
Aug 13, 2022 Aug 13, 2022

Copy link to clipboard

Copied

LATEST

Thank you @m1b  for helping me out on this

Votes

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