How to unlock a locked node?

Hi,

I am trying to run the code below, but it doesn’t work at all. Everytime I try to print selection.items on the console, it returns an empty array. Probably because locked nodes aren’t allowed to be handled. Not even a single error line has shown up. Would somebody help me out?

function unlockGrid(selection){
    selection.items.forEach((e) => {
        e.locked = false;
    });
}

As the documentation says, locked items cannot be selected. If you want to unlock nodes, let user select the parent like an artboard and run the plugin.

function myPluginCommand(selection) {
    selection.items[0].children.forEach(el => {
        // Assuming selection.items[0] is the parent of the locked nodes
        el.locked = false;
    })
}

module.exports = {
    commands: {
        myPluginCommand: myPluginCommand
    }
};

You’ll want to use itemsIncludingLocked instead of items. As Steve pointed out, locked items by definition can’t be selected – but XD does keep track of locked items that the user clicked or marqueed over. Those are the items that show the gray “locked object” decoration and what the built-in Object > Unlock command will operate on, so that is probably what you’re looking for.