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

Creating a selection, then fitting a text box inside.

Contributor ,
Feb 27, 2019 Feb 27, 2019

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:

Screen Shot 2019-02-27 at 15.44.59.png

Window Pop up :

Screen Shot 2019-02-27 at 15.47.57.png

Small Text Outcome:

Screen Shot 2019-02-27 at 15.49.14.png

Long Text Outcome:

Screen Shot 2019-02-27 at 15.51.06.png

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,

TOPICS
Actions and scripting

Views

1.5K

Translate

Translate

Report

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
Community Expert ,
Feb 27, 2019 Feb 27, 2019

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.

Votes

Translate

Translate

Report

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
Contributor ,
Feb 28, 2019 Feb 28, 2019

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?

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 28, 2019 Feb 28, 2019

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.

Votes

Translate

Translate

Report

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
LEGEND ,
Feb 28, 2019 Feb 28, 2019

Copy link to clipboard

Copied

caret* symbol

Votes

Translate

Translate

Report

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
Contributor ,
Feb 28, 2019 Feb 28, 2019

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,

Votes

Translate

Translate

Report

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
Contributor ,
Mar 04, 2019 Mar 04, 2019

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

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