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

Modify code to enter new text but within the boundaries of the document itself

Enthusiast ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

Welcome to the men of experience and knowledge
I have a code that writes a new text inside the document via Dilog using edittextbox
- But when writing texts with many lines, the text is created, but the line is very long, sometimes even reaching outside the document

- I want to modify this code so that the text is inserted like what was written inside the Dilog inside the edittextbox and the lines that were written are within the boundaries of the document itself

 

- I know there is an idea to edit that line
TextRef.contents = HW.text.replace(/\n/g,'\r');
In order to accept the insertion of lines in the same place they are inside the edittextbox

 

- This is the code that I relied on

dlg = new Window("dialog");   dlg.text = "Add New Text"; 
dlg.preferredSize  = [300, 150];

var HW = dlg.add("edittext", [0,0,500,300], "", {multiline: true, wantReturn: true}); HW.active=true;
HW.graphics.font = ScriptUI.newFont ("Arial", "Bold", 25);
Add=dlg.add("button", undefined, "Add Text"  );
Add.alignChildren = ['fill', 'fill'];

var docRef = app.activeDocument;
                var LayerRef = null;
                var TextRef = null;
                var pos = 0;
                

Add.onClick = function () {
LayerRef = docRef.artLayers.add();
                    LayerRef.kind = LayerKind.TEXT; 
                    TextRef = LayerRef.textItem;
                    TextRef.contents  = HW.text.replace(/\n/g,'\r'); 
                    TextRef.position = new Array(docRef.width/2, docRef.height/2);
                    preferences.rulerUnits = Units.CM;
                    TextRef.size = 45;
                    TextRef.kind = TextType.PARAGRAPHTEXT;
                    TextRef.font = 'Calibri-Bold';
                    TextRef.justification = Justification.CENTER;
                    TextRef.autoKerning = AutoKernType.METRICS;
                    TextRef.useAutoLeading = true;
dlg.close()
}
dlg.show();

 waiting for help

Thank You

TOPICS
Actions and scripting , SDK

Views

906

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 ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

If it is paragraph text the text must fit within the paragraph boundaries. If the text layer is not a Paragraph  text will not flow automatically you will need to add the new line carriage return into the text to flow the text and  position it over the canvas and set the font size  so the text will fit on canvas.  Text is very complex.  Skills above my pay grade is required.  To deal with size  you may need to change the document resolution to 72 for you size calculation  I believe font size is based on points being  72 pixels. Your script seems to add the artlayer makes its a text layer  position it document center and set its content from the dialog.  Size 45 Calibri-Bold.   There is no checking to see if the text  Size 45 Calibri-Bold will fit in the Document. No  document size check no checking of the canvases resolution.  The only constraint I see   may be "edittext", [0,0,500,300], "" but then I do not know ScriptUI  or know if the document canvas bounds is the  Paragraph Bounds.  Text is not something I script.  image.png

Here size 24pt is to large] where 18pt is fine.

Capture.jpg

 

 

 

JJMack

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 ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

Running you script it look like  the Document canvas size does become the Paragraph bounds and you positing  to the documents center so 3/4 of the paragraph area is off canvas.

 

image.png

Moving the layer more on canvas I see the bounds is not the canvas size perhaps its your dialog edit text areas

0,0 - 500,300 which is still taller than my canvas size

image.png

 

 

JJMack

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
Enthusiast ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

@JJMack 

Thank you for your interest and cooperation

I just want you to copy this article

If it is paragraph text the text must fit within the paragraph boundaries. If the text layer is not a Paragraph  text will not flow automatically you will need to add the new line carriage return into the text to flow the text and  position it over the canvas and set the font size  so the text will fit on canvas.  Text is very complex.  Skills above my pay grade is required.  To deal with size  you may need to change the document resolution to 72 for you size calculation  I believe font size is based on points being  72 pixels. Your script seems to add the artlayer makes its a text layer  position it document center and set its content from the dialog.  Size 45 Calibri-Bold.   There is no checking to see if the text  Size 45 Calibri-Bold will fit in the Document. No  document size check no checking of the canvases resolution.  The only constraint I see   may be "edittext", [0,0,500,300], "" but then I do not know ScriptUI  or know if the document canvas bounds is the  Paragraph Bounds.  Text is not something I script.  

Inside the edittextbox and click on ok and see what happens it will give you a long text that may reach outside the design limits
I want the text to fit within the borders of the document

 

 

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
Enthusiast ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

@JJMack 

For clarification, the article I wrote is for example and not for use

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 ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

You need to add logic to handle document size and text size the abount of text entered in your example is an example bad code.  Size matters.

JJMack

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
Enthusiast ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

@JJMack 

Well, I know that the code is bad.. Is there a suggestion or modification to the code to make the entered text consistent with the boundaries of the document

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 ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

Text is far from easy there are may characters set special characters  languages left to right etc.  Not my cup of tea... You need to handle sizes and the amount of text.. You need to add code to address the sizes. Document size.  The Paragraph area size and position over the canvas. Smallest Text print size you will  finds acceptable will limit the the number of characters the can be handled.  Language with long words can have adverse spacing issues and reduce the amount of  characters that can be handled.  Your ScriptUI edit text area may need to sized based one the current Documents size and resolution.    I do not script text much and what I have scripted is not always usable for any size document. The only suggestion I have is handle sizes.  Its your Document sizes and design, your Script and your boundaries. Size matters. Small text is not readable size matters. Handle sizes design well.

JJMack

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
Enthusiast ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

@JJMack 

I know this
But there is a method for this line TextRef.contents = HW.text.replace(/\n/g,'\r');
So that it works to divide the lines, but I do not know how this is done .. It is possible to divide the text into lines in order to reduce the width of the text and make it more consistent

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 ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

So you need to use different code set a var using  HW.text.replace(/\n/g,'\r') make it a string get its size parse it content etc handle its size.  Then set TextRef.contents with the proper amount of text and set TextRef.size and TextRef.font  for a good size and font for your document design.  I do not know how to handle text it to complex for my 80 year old brain. My eyes and brain can not handle regular expressions. Pecking the on a keyboard I always mess the up... good luck to ya...

 

JJMack

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 ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

You know this so do it.

JJMack

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
Enthusiast ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

Sorry if I could, I wouldn't have asked for help
- Well I have an idea
Is it possible to insert a line that scales the phragrahtext before inserting the text inside it?
So that it makes the phragrahtext fit with the size of the document and then the text is entered inside it

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 ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

Text characters are an ASCII code for a character in a character set it has no size  you have some amount of  text characters in a character font set font size you set to 45 may be relative to point size and document resolution you need pixels for character details and you need sufficient amount to form the characters and font size need the readable.  Your document canvas is X pixel wide and Y pixels  high and  pixels are displayed at some pixel density PPI.  Text is very complex.   You Document Canvas has a canvas size just so many pixels,  And you want text in some area over the canvas and you want the the text to be readable.    You need to set up some specifications requirement for what you want handle to know what is required for what you want to do.  Your Hail Mary Text will not fit in a document 100 px by 100 px and be readable.  Text is complex. Your design need to be do able You need the proper amount of canvas to handle a limited amount of text.    Many font have proportional characters and word length can cause spacing issues.    Design your process well.   A good design is required Text has many dependencies. 

JJMack

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 Beginner ,
Aug 02, 2023 Aug 02, 2023

Copy link to clipboard

Copied

LATEST

This is my windows photoshop scripts, but it's not working on mac sx photo selection path

 

// Open the Edges Collections directory

var strEdgeFXFolder = Folder.selectDialog ("~/Desktop/My Logo 1");

var edgeFXFile = strEdgeFXFolder .openDlg("Choose the egde you want to apply","JPEG/PNG:*JPG;*.JPEG;*.JPE;*.PNG;*.psd;*.PSD");

open (edgeFXFile)

 

help

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
Enthusiast ,
Dec 30, 2021 Dec 30, 2021

Copy link to clipboard

Copied

JJMack

God bless you in good health..
I am very happy with your cooperation

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