Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Explorer ,
Feb 25, 2012 Feb 25, 2012

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,

TOPICS
Scripting
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 25, 2012 Feb 25, 2012

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.

Translate
Adobe
Explorer ,
Feb 25, 2012 Feb 25, 2012

If this is too confusing, the biggest issue is getting the script to recognize the "If" statement. I have it in there as you can see from above, but the symbol is placed no matter what. It doesn't matter which dropdown item is selected. Is there another object that needs to be called out underneath the dropdown like myDropdown.value or selection?. If that could be answered, that would be a big help.

thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Feb 25, 2012 Feb 25, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 25, 2012 Feb 25, 2012

ok, thanks for the response. I have since figured that one out, but it's still ignoring the statement and placing the symbol anyway. Just let me know when you get the time. I appreciate it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Feb 25, 2012 Feb 25, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 25, 2012 Feb 25, 2012

No problem, thanks for keeping me on the radar Muppet.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2012 Feb 25, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 25, 2012 Feb 25, 2012

Thanks Carlos!! That did the trick. I have been spending days trying to figure that out and it was all about placement.. You definitely got this one, thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2012 Feb 25, 2012
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2012 Feb 25, 2012

Hi Mark, The Citizens won!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Feb 25, 2012 Feb 25, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2012 Feb 25, 2012

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

hahaha, good one

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines