Skip to main content
Question

Script to hide everything except nodes named 'logo'


Working on some tools to help split up files, this script is almost working, will hide everything except items with ‘logo’ in the name (and the frames they are in), but if the ‘logo’ node is a group with items like vectors inside it, those will be hidden.
Any ideas on what I am missing?


// Hide all layers except those with 'logo' in the name
function hideLayersExceptLogo(nodes) {
  nodes.forEach(node => {
    // Hide everything including frames
    node.visible = false;

    // Check if the node or any of its children contain 'Logo' in name
    let hasLogo = false;
    if (node.name && node.name.toLowerCase().includes('logo')) {
      hasLogo = true;
    } else if (node.type === 'FRAME') {
      node.findAll(n => {
        if (n.name && n.name.toLowerCase().includes('logo')) {
          hasLogo = true;
        }
      });
    }

    if (hasLogo) {
      // If the node or any of its children contain 'logo', unhide them
      node.visible = true;
      if ('children' in node) {
        node.children.forEach(child => {
          child.visible = true;
        });
      }
    }

    // Recursively hide children
    if ('children' in node) {   
      hideLayersExceptLogo(node.children);
    }
  });
}

This topic has been closed for replies.

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings