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.
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
...
Copy link to clipboard
Copied
Hi. It would make more sense to the community if you could show before and after pictures.
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
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);
})();
Copy link to clipboard
Copied
Amazing, thank you so much - ill try this out soon thank you!!!
Copy link to clipboard
Copied
Perfect, tested and its working beautifully thanks!
Copy link to clipboard
Copied
I will publish an improved version of the script in the future. I already have a few ideas.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
And please describe the kind of your textbox. (Because: 90% of point text does not make sense.)
Copy link to clipboard
Copied
Ive posted an image above if that helps.