Copy link to clipboard
Copied
Heyo everyone!
Im trying to make a list of all the comments ive added to my layers, but i dont want any duplicates.
I want add the items to a dropdownlist.
It seems it uses the if(found == false){ before the if(commentLayer
what it does now is create a new items for every comment including the duplicates.
This is the code i have now:
panel.Label.R3.refresh.onClick = function (){
alert("Refreshing list!");
var comp = app.project.activeItem;
var numlayer = comp.numLayers + 1;
for (i = 1; i < numlayer; i++){
var commentLayer = comp.layer(i).comment.split("|");
for (c = 0; c < commentLayer.length; c++) {
var found = false;
var numList = panel.Label.R3.L1.items;
for (k = 0; k < numList.length; k++) {
if(commentLayer
alert("found!")
found = true;
}
}
if(found == false){
panel.Label.R3.L1.add("item", commentLayer
panel.Label.R3.L1.selection = 0;
alert(found)
}
}
}
}
im kinda new to scripting so its possibly not the best way to do this
Do you guys know what im doing wrong? i cant figure it out.
Thanks in advance!
It might be because you are comparing a String with a ListItem.
Try replace if(commentLayer
by:
if (commentLayer
For a proper refresh, you'll probably need to do panel.Label.R3.L1.removeAll() before starting your loops (ie, empty the dropdownlist).
You can also prepare an array of all comments before starting to manipulate the dropdown. Might be easier. Something like this:
...function getAllLayerComments(comp){
var result = [];
var temp
Copy link to clipboard
Copied
It might be because you are comparing a String with a ListItem.
Try replace if(commentLayer
by:
if (commentLayer
For a proper refresh, you'll probably need to do panel.Label.R3.L1.removeAll() before starting your loops (ie, empty the dropdownlist).
You can also prepare an array of all comments before starting to manipulate the dropdown. Might be easier. Something like this:
function getAllLayerComments(comp){
var result = [];
var temp = {};
var n, comments, comm, i;
if (!(comp instanceof CompItem)) return result;
// run through layers
for (n=1; n<=comp.numLayers; n++){
if (comp.layer(n).comment.length==0) continue;
comments = comp.layer(n).comment.split("|");
// run through comment components:
for (i=0; i<comments.length; i++){
comm = comments;
if (temp.hasOwnProperty(comm)){
// already stored
continue;
}
else{
// store that comment
temp[comm] = 1;
};
};
};
// transform the temp object into an array
for (comm in temp){
if (temp[comm] === 1) result.push(comm);
};
// sort comments alphabetically
result.sort();
return result;
};
Xavier
Copy link to clipboard
Copied
Thanks man that worked for me!
sorry for my late response!