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

Script - Create dropdownlist from layer comments not working as intended

New Here ,
Nov 26, 2017 Nov 26, 2017

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 == panel.Label.R3.L1.items){ ??

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 == panel.Label.R3.L1.items){

                                       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!

TOPICS
Scripting

Views

533

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

Advocate , Nov 26, 2017 Nov 26, 2017

It might be because you are comparing a String with a ListItem.

Try replace if(commentLayer == panel.Label.R3.L1.items)

by:

if (commentLayer == panel.Label.R3.L1.items.text)

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

...

Votes

Translate

Translate
Advocate ,
Nov 26, 2017 Nov 26, 2017

Copy link to clipboard

Copied

It might be because you are comparing a String with a ListItem.

Try replace if(commentLayer == panel.Label.R3.L1.items)

by:

if (commentLayer == panel.Label.R3.L1.items.text)

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

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
New Here ,
Nov 27, 2017 Nov 27, 2017

Copy link to clipboard

Copied

LATEST

Thanks man that worked for me!

sorry for my late response!

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