Copy link to clipboard
Copied
My end goal is a script that the user writes their own text into a new window pop up, then that text is positioned in the bottom 10% of the image.
Start Image:
Window Pop up :
Small Text Outcome:
Long Text Outcome:
This is where I am currently:
#target Photoshop
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
var doc = app.activeDocument;
var hgt10 = doc.height / 10;
var FillColor = new SolidColor;
FillColor.rgb.hexValue = 'ff0000';
var newHgt = doc.height + hgt10
doc.resizeCanvas(doc.width, newHgt, AnchorPosition.TOPCENTER);
var win = new Window('dialog', "Custom Text");
var grp1 = win.add('group');
grp1.alignChildren = "top";
var txt = grp1.add('edittext', [0, 0, 300, 150], "Write your message", {multiline: true, scrolling: true});
txt.active = true;
var grp2 = win.add('group');
var goBtn = grp2.add('button', undefined, "Run");
grp2.add('button', undefined, "Cancel");
var newLyr = doc.artLayers.add();
newLyr.kind = LayerKind.TEXT;
// CONTENTS
var txtLyr = newLyr.textItem
txtLyr.font = "ArialMT"
txtLyr.contents = txt.text
var uV = new UnitValue(20,'mm')
txtLyr.size = UnitValue(25,'mm')
txtLyr.color = FillColor;
txtLyr.position = [25, 2200] // x, y - Need to fix position to fit in the lower 10%
goBtn.onClick = function() {
win.close();
}
win.show();
So the areas I would like some assistance with is:
1) Getting the text to be positioned in the new area (created by the resizeCanvas argument extending by 10%)
2) Adding line breaks and automatically sizing to fit a variety of length text files into the field.
Kind Regards,
Copy link to clipboard
Copied
I'm not sure there is a good way to do this. I ran across the same thing, and I had to resort to adding the line breaks manually, then applying the text, measuring it, then resizing it to fit in the area I wanted.
Copy link to clipboard
Copied
When you say you added line breaks manually, did you create an array within an if argument to create line breaks after x words/characters?
How did you go about that?
Copy link to clipboard
Copied
I was creating a way to put information in about images into the image. The information was pulled from the images metadata. The users would fill in things like description, title, and other fields using using Bridge. With the UI that I made, the user could then construct what metadata they wanted to use. To add a line break within a metadata field, I would have them insert the carrot symbol "^", as it was something that was never actually used. So my script would creat an array by splitting the text wherever there was that symbol.
Copy link to clipboard
Copied
caret* symbol
Copy link to clipboard
Copied
Ah I get you, unfortunately I want to avoid the need for having any additional input from users.
Basically the users will be inputting custom text in for each image depending on the usage rights and owners, which will vary from file to file.
So I need to be able to make it as simple as possible for users with no design/scripting knowledge. Without too much instruction so it can be used across languages.
So if you have any suggestions for achieving this either as I am attempting or any other possible solutions, that would be good.
Many Thanks,
Copy link to clipboard
Copied
Has anyone had any luck building text boxes with scripts in general? Maybe if I can sort that out I may be able to work out what I need to do to build upon my script.