Skip navigation
Currently Being Moderated

using Javascript and ScriptUI to create a form that brings in a symbol from library

Feb 25, 2012 4:34 AM

Tags: #illustrator #cs5 #buttons #dropdown #if #scriptui #dropdownboxes #conditionals

Hello everyone,

 

I've been trying to pull together the right info to use javascript to create a form to bring in particularsymbols from the symbol library based on the variables taken from the form. I've taken bits and pieces from various sample scripts and tried to make this work, but my problem appears when I try to use conditionals.

 

This is a limited version of what I want to do, but it is enough to get the point across.

 

1. I want to select a script that has various dropdown boxes. I would like the first dropdown to give me 3 options: 10, 13, 18

2. I would also like another drop down box that gives me three more options: single needle, double needle, and knife edge.

3. I would then like it to have an "ok" button and "Cancel" button.

4. From here when I click the ok button, a symbol is brought in from the library depending on what parameters were given to the form.

 

ex. If I selected 10 in the first drop down and double needle in the second, I would like "SYMBOL A" to be pulled from the library and centered on the artboard.

ex. If I selected 13 in the first drop down and double needle in the second, I would like "SYMBOL B" to be pulled from the library and centered on the artboard.

 

I've gotten the UI to pop up and it works as planned as well as bringing in a symbol, my problem comes when I try to incorporate conditionals and functions.

 

Here is my script. Please let me know what I'm doing wrong.

 

var myDoc = app.activeDocument;
var Pallette = new Window ("dialog", "Create a Shell");
Pallette.add ("statictext", undefined, "Fill Opening in Inches:");
Pallette.orientation = "row";
var myDropdown =  Pallette.add ("dropdownlist", undefined, ["10", "13", "18"]);
myDropdown.selection = 1;
var myButtonGroup =  Pallette.add ("group");
myButtonGroup.orientation = "column";
var btnCreate = myButtonGroup.add ("button", undefined, "OK");
MyFillSelection = myDropdown.selection
btnCreate.onClick = function () {
    if ( MyFillSelection = "13") {
               symbolRef = myDoc.symbols["SYMBOL A"];
        symbolItemRef1 = myDoc.symbolItems.add(symbolRef);
        
       redraw();
    } 

}
var btnCancel = myButtonGroup.add ("button", undefined, "Cancel");

  Pallette.show ();

 

If anyone has any input, it would be much appreciated.

 

thanks,

 
Replies
  • Currently Being Moderated
    Feb 25, 2012 9:33 AM   in reply to duhwellhuh

    Sorry I have not had the time just yet but I can say now the if ( condition == value ) single = assigns…

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2012 10:32 AM   in reply to duhwellhuh

    Half time… watching my man city at the moment… I will take a look though…

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2012 11:57 AM   in reply to duhwellhuh

    MyFillSelection = myDropdown.selection is outside the function, so it will always read "13", nothing is making the value change.

     

    move that line into your function and add the text property to it...MyFillSelection = myDropdown.selection.text;

     

    then do your if comparisons, that will do it.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2012 11:58 AM   in reply to Muppet Mark

    Hi Mark, The Citizens won!!!

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2012 12:36 PM   in reply to CarlosCanto

    Of cause they did… I can change the to now… do Carlos sort this… while ( mark.hasABeer == true );

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2012 12:49 PM   in reply to Muppet Mark

    do Carlos sort this… while ( mark.hasABeer == true );

    hahaha, good one

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 25, 2012 12:52 PM   in reply to duhwellhuh

    help gald to, welcome you are....yes, it is all about the placement

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points