Locking artboards using javascript

Hello,

im trying to create a button that locks all my Artboards.
Below is an example of my code:

function lockArtboards() {
    console.log("Locking Artboards");
    scenegraph.root.children.forEach((node) => {
        if (node instanceof Artboard) {
            node.locked = true;
            console.log(node.name + " - Locked: " + node.locked);
        }
    });
}

Result:

    node.locked = true;
                ^

Plugin TypeError: Cannot set property locked of [object Object] which has only a getter

i also tried using application.editDocument but i get same error:

function lockArtboards() {
    application.editDocument((selection) => { 
      scenegraph.root.children.forEach((node) => {
        if (node instanceof Artboard) {
           node.locked = true;
           console.log(node.name + " - Locked: " + node.locked);
       }
  }
});

Would anybody know how i can set all artboard layers to be locked within my javascript code?

Unfortunately XD does not allow artboards to be locked, so the plugin APIs cannot do that either. There is a feature request for that here:

1 Like

thank you! yes, i realized you cannot, i was actually trying to lock a background image inside the artboard so this post is irrelevant now, but thank you