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

Scale layer object height to same as text layer height

Explorer ,
Mar 10, 2019 Mar 10, 2019

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);

TOPICS
Actions and scripting
1.1K
Translate
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
Adobe
People's Champ ,
Mar 11, 2019 Mar 11, 2019

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);

Translate
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 ,
Mar 21, 2019 Mar 21, 2019

r-bin​,

Thanks for the answer. Could you please describe what this is doing?

  • What bound[3]/bound[1] represent?
  • Why multiple by 100?
Translate
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
People's Champ ,
Mar 21, 2019 Mar 21, 2019

Retsied 

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

Translate
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 ,
Apr 24, 2019 Apr 24, 2019

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);

Translate
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
People's Champ ,
Apr 25, 2019 Apr 25, 2019

Untitled-1.png

Everything is working.
The active layer must be a text layer. And the layer "My Art Layer" should be present and not be empty.
What error occurs?

Translate
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
Engaged ,
Apr 26, 2019 Apr 26, 2019

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.

0001.jpg

Translate
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
Engaged ,
Apr 26, 2019 Apr 26, 2019
LATEST

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);

Translate
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