Scripting: Dialogbox with user input text frames. Help!

New Here ,
Jan 06, 2021

Copy link to clipboard

Copied

Hey! I am new to the forums and new to scripting. I am working on a basic dialog box to help alleviate some very repetitive task.

 

Basically I have a dialog box appear with 3 fields for the user to enter information into. I want to take their data and have it placed into 3 different text frames on the page. This information would need populate in 3 different locations throughout the document.  Unfortunately  because I am still new to the world of scripting I am struggling to figure out how to do this. Below is the script that I have thus far. I was able to get everything working with my radio buttons just having issues approaching the input text. Honestly I am not even sure where to begin, I keep finding conflicting data and have gotten overwhelmed and confused.

 

Any help or guidance would be great appreciated.

 

// DIALOG

// ======

var dialog = new Window("dialog");

    dialog.text = "Enter Text";

    dialog.preferredSize.width = 250;

    dialog.orientation = "column";

    dialog.alignChildren = ["center","top"];

    dialog.spacing = 10;

    dialog.margins = 16;

 

// GROUP1

// ======

var group1 = dialog.add("group", undefined, {name: "group1"});

    group1.orientation = "row";

    group1.alignChildren = ["left","center"];

    group1.spacing = 10;

    group1.margins = 0;

 

// PANEL1

// ======

var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});

    panel1.text = "Text";

    panel1.orientation = "column";

    panel1.alignChildren = ["left","top"];

    panel1.spacing = 10;

    panel1.margins = 10;

 

var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});

    statictext1.text = "Small text 1";

    statictext1.preferredSize.width = 250;

 

var edittext1 = panel1.add('edittext {properties: {name: "edittext1"}}');

    edittext1.text = "Edit Text";

    edittext1.preferredSize.width = 250;

 

var statictext2 = panel1.add("statictext", undefined, undefined, {name: "statictext2"});

    statictext2.text = "Large Text";

 

var edittext2 = panel1.add('edittext {properties: {name: "edittext2"}}');

    edittext2.text = "Edit Text";

    edittext2.preferredSize.width = 250;

 

var statictext3 = panel1.add("statictext", undefined, undefined, {name: "statictext3"});

    statictext3.text = "Small Text 2";

 

var edittext3 = panel1.add('edittext {properties: {name: "edittext3"}}');

    edittext3.text = "Edit Text";

    edittext3.preferredSize.width = 250;

 

// PANEL2

// ======

var panel2 = group1.add("panel", undefined, undefined, {name: "panel2"});

    panel2.text = "Color";

    panel2.orientation = "column";

    panel2.alignChildren = ["left","top"];

    panel2.spacing = 10;

    panel2.margins = 10;

 

var radiobutton1 = panel2.add("radiobutton", undefined, undefined, {name: "radiobutton1"});

    radiobutton1.text = "Blue";

   

var radiobutton2 = panel2.add("radiobutton", undefined, undefined, {name: "radiobutton2"});

    radiobutton2.text = "Red";

   

var radiobutton3 = panel2.add("radiobutton", undefined, undefined, {name: "radiobutton3"});

    radiobutton3.text = "White";

 

// GROUP2

// ======

var group2 = dialog.add("group", undefined, {name: "group2"});

    group2.orientation = "row";

    group2.alignChildren = ["left","center"];

    group2.spacing = 10;

    group2.margins = 0;

 

var button1 = group2.add("button", undefined, undefined, {name: "button1"});

    button1.text = "OK";

 

var button2 = group2.add("button", undefined, undefined, {name: "button2"});

    button2.text = "Cancel";

 

dialog.show();

 

// RADIO INPUT

// ======

var doc = app.activeDocument;

 

    if (radiobutton1.value == true)

{

    doc.objectStyles.itemByName("SM_Background").fillColor = "Baker Blue";

    doc.objectStyles.itemByName("SM_Bar").fillColor = "Bright Red";

    doc.paragraphStyles.itemByName("SM_Large_Twitter").fillColor = "White";

    doc.paragraphStyles.itemByName("SM_Small_Twitter").fillColor = "White";

 

}

 

    if (radiobutton2.value == true)

{

    doc.objectStyles.itemByName("SM_Background").fillColor = "Medium Red";

    doc.objectStyles.itemByName("SM_Bar").fillColor = "Bright Red";

    doc.paragraphStyles.itemByName("SM_Large_Twitter").fillColor = "White";

    doc.paragraphStyles.itemByName("SM_Small_Twitter").fillColor = "White";

 

}

 

    if (radiobutton3.value == true)

{

    doc.objectStyles.itemByName("SM_Background").fillColor = "Background Grey";

    doc.objectStyles.itemByName("SM_Bar").fillColor = "Bright Red";

    doc.paragraphStyles.itemByName("SM_Large_Twitter").fillColor = "Medium Red";

    doc.paragraphStyles.itemByName("SM_Small_Twitter").fillColor = "Dark Grey";

 

}

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

How do you want to add the text to defined locations in your document. If they are named Text Frames (ie, named in your layers panel), then you can do something like: 

 

doc.textFrames.itemByName("editBox").contents = edittext1.text; 

 

Otherwise, you need to draw them with doc.textFrames.add(); which will create and return a new text frame. You can specify its location and other properties in the constructor. Have a look here. To add a frame on the last page of the doc, with a size that's the same as the page:

 

var doc = app.documents[0];
var tf = doc.pages.lastItem().textFrames.add(
  { geometricBounds: doc.pages.lastItem().bounds }
);
tf.contents = edittext1.text;

 

 

TOPICS
Scripting

Views

37

Likes

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

Scripting: Dialogbox with user input text frames. Help!

New Here ,
Jan 06, 2021

Copy link to clipboard

Copied

Hey! I am new to the forums and new to scripting. I am working on a basic dialog box to help alleviate some very repetitive task.

 

Basically I have a dialog box appear with 3 fields for the user to enter information into. I want to take their data and have it placed into 3 different text frames on the page. This information would need populate in 3 different locations throughout the document.  Unfortunately  because I am still new to the world of scripting I am struggling to figure out how to do this. Below is the script that I have thus far. I was able to get everything working with my radio buttons just having issues approaching the input text. Honestly I am not even sure where to begin, I keep finding conflicting data and have gotten overwhelmed and confused.

 

Any help or guidance would be great appreciated.

 

// DIALOG

// ======

var dialog = new Window("dialog");

    dialog.text = "Enter Text";

    dialog.preferredSize.width = 250;

    dialog.orientation = "column";

    dialog.alignChildren = ["center","top"];

    dialog.spacing = 10;

    dialog.margins = 16;

 

// GROUP1

// ======

var group1 = dialog.add("group", undefined, {name: "group1"});

    group1.orientation = "row";

    group1.alignChildren = ["left","center"];

    group1.spacing = 10;

    group1.margins = 0;

 

// PANEL1

// ======

var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});

    panel1.text = "Text";

    panel1.orientation = "column";

    panel1.alignChildren = ["left","top"];

    panel1.spacing = 10;

    panel1.margins = 10;

 

var statictext1 = panel1.add("statictext", undefined, undefined, {name: "statictext1"});

    statictext1.text = "Small text 1";

    statictext1.preferredSize.width = 250;

 

var edittext1 = panel1.add('edittext {properties: {name: "edittext1"}}');

    edittext1.text = "Edit Text";

    edittext1.preferredSize.width = 250;

 

var statictext2 = panel1.add("statictext", undefined, undefined, {name: "statictext2"});

    statictext2.text = "Large Text";

 

var edittext2 = panel1.add('edittext {properties: {name: "edittext2"}}');

    edittext2.text = "Edit Text";

    edittext2.preferredSize.width = 250;

 

var statictext3 = panel1.add("statictext", undefined, undefined, {name: "statictext3"});

    statictext3.text = "Small Text 2";

 

var edittext3 = panel1.add('edittext {properties: {name: "edittext3"}}');

    edittext3.text = "Edit Text";

    edittext3.preferredSize.width = 250;

 

// PANEL2

// ======

var panel2 = group1.add("panel", undefined, undefined, {name: "panel2"});

    panel2.text = "Color";

    panel2.orientation = "column";

    panel2.alignChildren = ["left","top"];

    panel2.spacing = 10;

    panel2.margins = 10;

 

var radiobutton1 = panel2.add("radiobutton", undefined, undefined, {name: "radiobutton1"});

    radiobutton1.text = "Blue";

   

var radiobutton2 = panel2.add("radiobutton", undefined, undefined, {name: "radiobutton2"});

    radiobutton2.text = "Red";

   

var radiobutton3 = panel2.add("radiobutton", undefined, undefined, {name: "radiobutton3"});

    radiobutton3.text = "White";

 

// GROUP2

// ======

var group2 = dialog.add("group", undefined, {name: "group2"});

    group2.orientation = "row";

    group2.alignChildren = ["left","center"];

    group2.spacing = 10;

    group2.margins = 0;

 

var button1 = group2.add("button", undefined, undefined, {name: "button1"});

    button1.text = "OK";

 

var button2 = group2.add("button", undefined, undefined, {name: "button2"});

    button2.text = "Cancel";

 

dialog.show();

 

// RADIO INPUT

// ======

var doc = app.activeDocument;

 

    if (radiobutton1.value == true)

{

    doc.objectStyles.itemByName("SM_Background").fillColor = "Baker Blue";

    doc.objectStyles.itemByName("SM_Bar").fillColor = "Bright Red";

    doc.paragraphStyles.itemByName("SM_Large_Twitter").fillColor = "White";

    doc.paragraphStyles.itemByName("SM_Small_Twitter").fillColor = "White";

 

}

 

    if (radiobutton2.value == true)

{

    doc.objectStyles.itemByName("SM_Background").fillColor = "Medium Red";

    doc.objectStyles.itemByName("SM_Bar").fillColor = "Bright Red";

    doc.paragraphStyles.itemByName("SM_Large_Twitter").fillColor = "White";

    doc.paragraphStyles.itemByName("SM_Small_Twitter").fillColor = "White";

 

}

 

    if (radiobutton3.value == true)

{

    doc.objectStyles.itemByName("SM_Background").fillColor = "Background Grey";

    doc.objectStyles.itemByName("SM_Bar").fillColor = "Bright Red";

    doc.paragraphStyles.itemByName("SM_Large_Twitter").fillColor = "Medium Red";

    doc.paragraphStyles.itemByName("SM_Small_Twitter").fillColor = "Dark Grey";

 

}

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

How do you want to add the text to defined locations in your document. If they are named Text Frames (ie, named in your layers panel), then you can do something like: 

 

doc.textFrames.itemByName("editBox").contents = edittext1.text; 

 

Otherwise, you need to draw them with doc.textFrames.add(); which will create and return a new text frame. You can specify its location and other properties in the constructor. Have a look here. To add a frame on the last page of the doc, with a size that's the same as the page:

 

var doc = app.documents[0];
var tf = doc.pages.lastItem().textFrames.add(
  { geometricBounds: doc.pages.lastItem().bounds }
);
tf.contents = edittext1.text;

 

 

TOPICS
Scripting

Views

38

Likes

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
Jan 06, 2021 0
Adobe Community Professional ,
Jan 06, 2021

Copy link to clipboard

Copied

How do you want to add the text to defined locations in your document. If they are named Text Frames (ie, named in your layers panel), then you can do something like: 

 

doc.textFrames.itemByName("editBox").contents = edittext1.text; 

 

Otherwise, you need to draw them with doc.textFrames.add(); which will create and return a new text frame. You can specify its location and other properties in the constructor. Have a look here. To add a frame on the last page of the doc, with a size that's the same as the page:

 

var doc = app.documents[0];
var tf = doc.pages.lastItem().textFrames.add(
  { geometricBounds: doc.pages.lastItem().bounds }
);
tf.contents = edittext1.text;

 

 

Likes

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
Reply
Loading...
Jan 06, 2021 0
Cjmajor4 LATEST
New Here ,
Jan 06, 2021

Copy link to clipboard

Copied

Thank you! This was exactly what I was looking for. I knew it had to be simple!

 

Thank you again!

Likes

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
Reply
Loading...
Jan 06, 2021 0