Skip to main content
Known Participant
August 13, 2022
Answered

List appearing after prompt

  • August 13, 2022
  • 1 reply
  • 231 views

Thank you for taking the time to look at this posting!
I hope this is a simple problem. I have a script that displays a list of choices, and then I prompt the user to select one. My problem is that the prompt appears before the list. I tried to insert an “alert” just after running the line to display the list (testFrame.contents = variable). I tried to sleep for a while – computer didn’t like but I did. Not sure where to go from here.
The following is a test script created to demonstrate the problem:


// Add a text Frame - called myIdeaList
var myIdeaList = app.activeDocument.textFrames.add();
// Set font for list
myIdeaList.textRange.characterAttributes.textFont = app.textFonts.getByName("Cent");
// Set size of characters in list
myIdeaList.textRange.characterAttributes.size = 24;
// Set position of list
myIdeaList.position = new Point(50, -50);
// Display list of ideas
myIdeaList.contents = ("Work on script\nClean your Cave\nPick your nose\nTake a Nap");
// Ask to select one from list
var NeXT = prompt("Please pick an idea from the list", "", "Have a pick but not your nose.");
// Display which item selected
alert (NeXT);


Thank you for your advise!

This topic has been closed for replies.
Correct answer Charu Rajput

Hi,

The code is running as expected. When you say, display a list of choices, what does it excatly mean here?

You are setting the contents of the textframe. If you want to see the contents of the textfarme before the prompt then try below version

 

// Add a text Frame - called myIdeaList
var myIdeaList = app.activeDocument.textFrames.add();
// Set font for list
myIdeaList.textRange.characterAttributes.textFont = app.textFonts.getByName("Arial-Black");
// Set size of characters in list
myIdeaList.textRange.characterAttributes.size = 24;
// Set position of list
myIdeaList.position = new Point(50, -50);
// Display list of ideas
myIdeaList.contents = ("Work on script\nClean your Cave\nPick your nose\nTake a Nap");
app.redraw();
// Ask to select one from list
var NeXT = prompt("Please pick an idea from the list", "", "Have a pick but not your nose.");
// Display which item selected
alert (NeXT);

 

 

I am using the font which is available on my machine.

1 reply

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
August 13, 2022

Hi,

The code is running as expected. When you say, display a list of choices, what does it excatly mean here?

You are setting the contents of the textframe. If you want to see the contents of the textfarme before the prompt then try below version

 

// Add a text Frame - called myIdeaList
var myIdeaList = app.activeDocument.textFrames.add();
// Set font for list
myIdeaList.textRange.characterAttributes.textFont = app.textFonts.getByName("Arial-Black");
// Set size of characters in list
myIdeaList.textRange.characterAttributes.size = 24;
// Set position of list
myIdeaList.position = new Point(50, -50);
// Display list of ideas
myIdeaList.contents = ("Work on script\nClean your Cave\nPick your nose\nTake a Nap");
app.redraw();
// Ask to select one from list
var NeXT = prompt("Please pick an idea from the list", "", "Have a pick but not your nose.");
// Display which item selected
alert (NeXT);

 

 

I am using the font which is available on my machine.

Best regards
Known Participant
August 13, 2022

Perfect Charu Rajput!

Many many thanks.

I guess I am used to a liner execution of commands.  New to Illustrator scripting.  Boy do I have a lot to learn!

Outstanding,