Hi,
I'm working on script where user can put the square brackets around some text and that text will be different color.
The script is working when user enter the one pair of brackets and in only in one line. For example "Enter [your] text here".
But it doesn't work in multi line and when you try to add more brackets, for example "Enter [your] text [here]".
This is the script:
{ function myScript(thisObj){ function myScript_buildUI(thisObj){ var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", undefined, {resizeable:true}); //================================================================================================================ var textBox = myPanel.add("edittext", undefined, "Enter [your] text here!", {multiline:true}); textBox.minimumSize = [284,100]; var myButton = myPanel.add("button",undefined,"CREATE TEXT"); myButton.onClick = createMain; //================================================================================================================ function createMain(){ var textBoxContents = textBox.text; var lines = textBoxContents.replace(/ {1,}/g,"[").replace(/\[{1,}/g," ").replace(/ {1,}/g,"]").replace(/\]{1,}/g," ").split(/\n|\r/); var indexStart = textBoxContents.indexOf("["); var indexEnd = textBoxContents.indexOf("]"); createText(lines,indexStart,indexEnd); } function createText(line,start,end){ for (var i = 0; i < line.length; i++) { var myLayer = app.project.activeItem.layers.addText(line[i]); indexStartEnd(1); function indexStartEnd(prop){ for (var i = 0; i < line.length; i++) { myLayer.property("ADBE Text Properties").property(4).addProperty("ADBE Text Animator"); var txtProp = myLayer.property("ADBE Text Properties").property(4).property(1); txtProp.property("ADBE Text Animator Properties").addProperty("ADBE Text Fill Color"); txtProp.property(1).addProperty("ADBE Text Selector"); txtProp.property(1).property(prop).property(7).property("ADBE Text Range Units").setValue(2); txtProp.property(1).property(prop).property("ADBE Text Index Start").setValue(start); txtProp.property(1).property(prop).property("ADBE Text Index End").setValue(end); txtProp.property(2).property("ADBE Text Fill Color").setValue([0,0.6,0,1]); } } } } //================================================================================================================ myPanel.layout.layout(true); myPanel.minimumSize = myPanel.size; myPanel.layout.resize(); myPanel.onResizing = myPanel.onResize = function(){this.layout.resize()}; return myPanel; } var myScriptPal = myScript_buildUI (thisObj); if((myScriptPal != null) && (myScriptPal instanceof Window)){ myScriptPal.center(); myScriptPal.show(); } } myScript(this); }