Copy link to clipboard
Copied
I have 2 layers, 1 is an art layer object, the other is a pure text layer of fixed width. How can I extract the text layer height and use this to set the art layer to the same exact height. I need this to update dynamically, so if I change the texts height, the art layer automatically follows. So copy/paste hard numbers will not work.
I figured I could do this using activeLayer.bounds in some way, but couldn't get this to work.
Any ideas much appreciated, thanks!
My attempt:
doc.activeLayer = doc.artLayers.getByName("TextLayer");
var LB = doc.activeLayer.bounds;
var textHeight = LB[3].value;
doc.activeLayer = doc.artLayers.getByName("ArtLayer");
doc.activeLayer.resize(undefined, textHeight, AnchorPosition.MIDDLECENTER);
Copy link to clipboard
Copied
var doc = activeDocument;
var t = doc.artLayers.getByName("TextLayer");
var a = doc.artLayers.getByName("ArtLayer");
var textHeight = t.bounds[3].value - t.bounds[1].value;
var artHeight = a.bounds[3].value - a.bounds[1].value;
a.resize(undefined, textHeight/artHeight*100, AnchorPosition.MIDDLECENTER);
Copy link to clipboard
Copied
r-bin​,
Thanks for the answer. Could you please describe what this is doing?
Copy link to clipboard
Copied
Thanks for the answer. Could you please describe what this is doing?
- What bound[3]/bound[1] represent?
- Why multiple by 100?
1. Where did you see this?
2 Because you need to specify a percentage
Copy link to clipboard
Copied
r-bin​,
I mean what does bound[3] and bound[1] represent? And why divide the two in the resize function to force the artLayer to the same height as the textLayer?
I ask because I'm trying to do the same exact thing with a different file, with width instead of height and it won't work:
var doc = activeDocument;
var t = doc.activeLayer;
var textWidth = t.bounds[2].value - t.bounds[0].value;
var bub = doc.artLayers.getByName("My Art Layer");
var a = bub.duplicate();
var artWidth = a.bounds[2].value - a.bounds[0].value;
a.resize(textWidth/artWidth*100, undefined, AnchorPosition.MIDDLERIGHT);
Copy link to clipboard
Copied

Copy link to clipboard
Copied
Hi r-bin, great job! this inspires me in some projects. How do I keep the proportion of the object in that same example written by you? Thank you.

Copy link to clipboard
Copied
Disregard my question, I have already found an alternative with some changes.
activeDocument.activeLayer = activeDocument.activeLayer;
var LB = activeDocument.artLayers.getByName("TextLayer").bounds;
var IB = activeDocument.artLayers.getByName("ArtLayer").bounds;
var height = LB[3]-LB[1]; dheight = IB[3]-IB[1];
var porcentage = ((height/dheight)*100);
app.activeDocument.activeLayer.resize(porcentage, porcentage, AnchorPosition.MIDDLECENTER);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now