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

How to put multiple values into an array?

Participant ,
Jul 10, 2019 Jul 10, 2019

Copy link to clipboard

Copied

With this part of code, I am trying to put all found layer names (layersData) into dropdownlist2_array, but instead of a list with names, I get one line with all names!!! Any idea what am I doing wrong? Thank you in advance!!!

var layerNames = [];

for (var i = 0; i < layersData.length; i++)

{

    var layerName;

    layerName = layersData.name;

    layerNames.push(layerName);

};

var dropdownlist2_array = [layerNames];

var dropdownlist2 = panel2.add("dropdownlist", undefined, dropdownlist2_array);

dropdownlist2.selection = -1;

dropdownlist2.text = "Layer Name:";

image.jpg

TOPICS
Actions and scripting

Views

944

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
community guidelines

correct answers 1 Correct answer

Guide , Jul 10, 2019 Jul 10, 2019

var w = new Window("dialog","test",undefined,{closeButton: true});

var layerNames = []; 

var layersData=activeDocument.layers;

for (var i = 0; i < layersData.length; i++)  { 

    layerNames.push(layersData.name); 

}    

var dropdownlist2 = w.add("dropdownlist", undefined, layerNames);  

dropdownlist2.selection = 0;  

dropdownlist2.text = "Layer Name:";

w.show();

Votes

Translate

Translate
Adobe
Guide ,
Jul 10, 2019 Jul 10, 2019

Copy link to clipboard

Copied

var w = new Window("dialog","test",undefined,{closeButton: true});

var layerNames = []; 

var layersData=activeDocument.layers;

for (var i = 0; i < layersData.length; i++)  { 

    layerNames.push(layersData.name); 

}    

var dropdownlist2 = w.add("dropdownlist", undefined, layerNames);  

dropdownlist2.selection = 0;  

dropdownlist2.text = "Layer Name:";

w.show();

Votes

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
community guidelines
Participant ,
Jul 10, 2019 Jul 10, 2019

Copy link to clipboard

Copied

One more question... What should I do If I want to avoid duplicates? Thank you for your time!!!

Votes

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
community guidelines
Guide ,
Jul 10, 2019 Jul 10, 2019

Copy link to clipboard

Copied

var w = new Window("dialog","test",undefined,{closeButton: true});

var layerNames = []; 

var layersData=activeDocument.layers;

for (var i = 0; i < layersData.length; i++)  { 

    layerNames.push(layersData.name); 

}   

layerNames = UniqueSortedList(layerNames);

var dropdownlist2 = w.add("dropdownlist", undefined, layerNames);  

dropdownlist2.selection = 0;  

dropdownlist2.text = "Layer Name:";

w.show();

function UniqueSortedList(ArrayName){

var unduped = new Object;

for (var i = 0; i < ArrayName.length; i++) {  

unduped[ArrayName] = ArrayName;

}

var uniques = new Array;for (var k in unduped) {

   uniques.push(unduped);}

return uniques.sort();

}

Votes

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
community guidelines
Participant ,
Jul 10, 2019 Jul 10, 2019

Copy link to clipboard

Copied

LATEST

Thank you so much!!!

Votes

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
community guidelines