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

Script: Make rectangle based on size of object on layer

Explorer ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

Hello beautiful minds,
Would anyone happen to know how to make the following work in a script, if its possible:

 

Create a rectangle, based on the height(100%) of a text box, and the width(90%) of the same textbox.
Then have it go to page center.

Thanks for any help, let me know if you have any questions.

TOPICS
Scripting

Views

1.6K

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

Enthusiast , Dec 02, 2022 Dec 02, 2022

Change the percentage (decimal) in the "ratio".

(function (){
  if (!documents.length) return;
  if (!selection.length || selection[0].typename !== 'TextFrame') return;
  var ratio = 0.9 // Width scale
  var tf = selection[0];
  var color = new RGBColor();
  color.red = 255;
  color.green = 0;
  color.blue = 0;

  var dup = tf.duplicate().createOutline();
  var bnds = dup.geometricBounds;
  dup.remove();
  var w = Math.abs(bnds[2] - bnds[0]);
  var h = Math.abs(bnds[3] - bnds[1]);
  var top = bnd
...

Votes

Translate

Translate
Adobe
Enthusiast ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

Hi. It would make more sense to the community if you could show before and after pictures.

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
Explorer ,
Dec 02, 2022 Dec 02, 2022

Copy link to clipboard

Copied

So I would like to be able to run a script, that automatically creates the red rectangle you see behind the text.
Its the same height as the text, but slightly smaller width - possibly 90% ish

Screenshot 2022-12-02 at 15.48.17.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
Enthusiast ,
Dec 02, 2022 Dec 02, 2022

Copy link to clipboard

Copied

Change the percentage (decimal) in the "ratio".

(function (){
  if (!documents.length) return;
  if (!selection.length || selection[0].typename !== 'TextFrame') return;
  var ratio = 0.9 // Width scale
  var tf = selection[0];
  var color = new RGBColor();
  color.red = 255;
  color.green = 0;
  color.blue = 0;

  var dup = tf.duplicate().createOutline();
  var bnds = dup.geometricBounds;
  dup.remove();
  var w = Math.abs(bnds[2] - bnds[0]);
  var h = Math.abs(bnds[3] - bnds[1]);
  var top = bnds[1];
  var left = bnds[0] + w * 0.5 * (1 - ratio);

  var rect = tf.layer.pathItems.rectangle(top, left, w * ratio, h);
  rect.fillColor = color;
  rect.stroked = false;
  rect.move(tf, ElementPlacement.PLACEAFTER);
})();

 Screenshot 2022-12-02 at 21.32.24.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
Explorer ,
Dec 05, 2022 Dec 05, 2022

Copy link to clipboard

Copied

Amazing, thank you so much - ill try this out soon thank you!!!

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
Explorer ,
Dec 05, 2022 Dec 05, 2022

Copy link to clipboard

Copied

Perfect, tested and its working beautifully thanks!

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
Enthusiast ,
Dec 05, 2022 Dec 05, 2022

Copy link to clipboard

Copied

I will publish an improved version of the script in the future. I already have a few ideas.

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
Enthusiast ,
Dec 25, 2022 Dec 25, 2022

Copy link to clipboard

Copied

LATEST

From the small initial script in this thread, I created "HighlightText" — the paid script ($6) for adding highlighting strokes based on text lines: https://www.buymeacoffee.com/aiscripts/e/231626

Features:

- Use % or an absolute value for width and height of strokes. Units: px, pt, in, mm, cm, m, ft, yd

- Type 'fit' (no quotes) to use the full width of the area

- Choose x-height, Cap Height or custom letter to define the relative height

- Set the individual alignment of strokes relative to text lines with the anchor point selector

- Set the distance to move strokes in the vertical direction with Y Offset

- Edit numeric values faster with arrow keys or left & right brackets

- Automatic RGB and CMYK mode detection

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 ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

And please describe the kind of your textbox. (Because: 90% of point text does not make sense.)

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
Explorer ,
Dec 02, 2022 Dec 02, 2022

Copy link to clipboard

Copied

Ive posted an image above if that helps.

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