Modify code to enter new text but within the boundaries of the document itself
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