How to select ALL layers with a specific name?

I want to select all layers in my project with the name “.note”, so I have this code:

documentRoot.children.forEach(node => {                             
        if (node instanceof Artboard) {                                  
            let artboard = node;
            let notes = artboard.children.filter(artboardChild => { 
 return artboardChild.name == ".note";
            })
            notes.forEach(note => {                           
        //do stuff             
            })
        }
    })

The problem is that if I have a layer “.note” that is inside a group, it is not selected. How can I select ALL layers with this name, even if it’s inside a group?

1 Like

That, unfortunately, won’t be possible due to the edit context.

For nodes inside the current edit context, you could, e.g., add them to an array and then set the selction to that array:

selection.items = myNodes;

But that will – as stated – only work if all nodes in myNodes are inside the current edit context.

All in all, it is therefore (for now) not possible to achieve what you’re trying to do with the plugin APIs.

Hope this helps,
Best,
Pablo

References

https://adobexdplatform.com/plugin-docs/reference/selection.html#selectionitems--arrayscenenode:

The selection can only contain items which are in the current edit context.

https://adobexdplatform.com/plugin-docs/reference/selection.html#selection:

The selection cannot contain both a node and one of its ancestors at the same time.

(what if a Group and a child node contain '.note' in its name? :wink:)