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

Select text frame and add document/artboard dimension

Participant ,
Oct 24, 2017 Oct 24, 2017

Copy link to clipboard

Copied

Hi, Im looking for a simple script which will check the dimensions of an artboard and populate a selected text frame with the size. It would be great if you was working to a scale and you could select the scale option and then the script calculates the dimensions and adds this to the text frame. (I guess thats two parts).

Anyone know of a script that can do this.? I have found a great script which you can select an object and then apply the script to add mark up with a scale option, but I just want to add a simple string to a text frame.

GitHub - adamdehaven/Specify: A script to automate specifying dimensions (and adding dimension lines...

can anyone help?

lister

TOPICS
Scripting

Views

525

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

Contributor , Nov 19, 2017 Nov 19, 2017

Select only one text frame and execute this script.

Then the active artboard size is populated in the selected text frame.

Like this?

(function () {

   

    var doc,

        sel,

        rect,

        w,

        h,

        unitType = "";

   

    if (app.documents.length === 0) {

        alert("Open Document.");

        return;

    }

    doc = app.activeDocument;

    sel = doc.selection;

   

    if (sel.length !== 1) {

        alert("Select only one TextFrameItem.");

        return;

    }

    if (!sel[0].constructor

...

Votes

Translate

Translate
Adobe
Contributor ,
Nov 19, 2017 Nov 19, 2017

Copy link to clipboard

Copied

LATEST

Select only one text frame and execute this script.

Then the active artboard size is populated in the selected text frame.

Like this?

(function () {

   

    var doc,

        sel,

        rect,

        w,

        h,

        unitType = "";

   

    if (app.documents.length === 0) {

        alert("Open Document.");

        return;

    }

    doc = app.activeDocument;

    sel = doc.selection;

   

    if (sel.length !== 1) {

        alert("Select only one TextFrameItem.");

        return;

    }

    if (!sel[0].constructor.name === "TextFrameItem") {

        alert("Select only one TextFrameItem.");

        return;

    }

    switch (doc.rulerUnits) {

    case RulerUnits.Centimeters:

        unitType = "cm";

        break;

    case RulerUnits.Inches:

        unitType = "in";

        break;

    case RulerUnits.Millimeters:

        unitType = "mm";

        break;

    case RulerUnits.Picas:

        unitType = "pc";

        break;

    case RulerUnits.Points:

        unitType = "pt";

        break;

    case RulerUnits.Pixels:

        unitType = "px";

        break;

    default:

        return;

    }

   

    rect = doc.artboards[doc.artboards.getActiveArtboardIndex()].artboardRect;

    w = Math.round(Number(new UnitValue(rect[2] - rect[0], "pt").as(unitType)) * 100) / 100;

    h = Math.round(Number(new UnitValue(rect[1] - rect[3], "pt").as(unitType)) * 100) / 100;

   

    sel[0].contents = "" + w + unitType + ", " + h + unitType;

   

}());

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