Is it possible to make scriptui multiline text work with set width but no height

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: xbytor, DavideBarranca, Paul MR

Post Reply
User avatar
joonaspaakko
Posts: 6
Joined: Mon Apr 16, 2018 8:53 am

Is it possible to make scriptui multiline text work with set width but no height

Post by joonaspaakko » Wed Dec 12, 2018 1:37 pm

I'd ideally like to set a width to a multiline statictext item and have the height match content height, but ScriptUI seems to have issues with this. It seems like it calculates the height before the width is defined... so when the width is set, the text flow changes leaving bunch of whitespace below the text (example image below).

I'm essentially trying to solve the same issue as in this post in Adobe forums. The solution there does not work very reliably. It specifically seems to fail in Photoshop. I need it to work in all apps.

This code below is a little test case where I was trying to figure out a way to make sure the height is calculated based on the content height, but it's not doing anything. I figured I should somehow reset the height... but that doesn't seem possible.

Any ideas?

Code: Select all


var dialog = new Window("dialog");
dialog.margins = 0;

var statictext1 = dialog.add("statictext", undefined, undefined, {multiline: true});
statictext1.text = "Vivamus a enim pretium, posuere lorem ac, suscipit ipsum. Quisque eget tempus ligula, nec porta erat. Curabitur facilisis tristique dui at suscipit. Sed sit amet feugiat sem. Aenean viverra, ligula sed finibus blandit, leo justo vulputate tellus.";

dialog.onShow = function() {
$.writeln('- - - - - - - -');
$.writeln( 'Width (before): ' + statictext1.bounds.width );
$.writeln( 'Height (before): ' + statictext1.bounds.height );
statictext1.size.width = 338;
dialog.layout.layout(true);
// dialog.layout.resize();
$.writeln('→');
$.writeln( 'Width (after): ' + statictext1.bounds.width );
$.writeln( 'Height (after): ' + statictext1.bounds.height );
};

dialog.show();
img.png
img.png (128.65 KiB) Viewed 1264 times

Post Reply