I’m getting an error when I attempt to add an element to the artboard from a panel.
async function addRectangle(event) {
const {selection} = require("scenegraph");
try {
const newElement = new Rectangle();
newElement.width = 100;
newElement.height = 100;
newElement.fill = new Color("Purple");
editDocument( () => {
selection.insertionParent.addChild(newElement);
newElement.moveInParentCoordinates(100, 100);
});
}
catch(error) {
console.log(error);
}
}
Plugin Error: Plugin is not permitted to make changes from the background. Use editDocument() for panel UI handlers, or return a Promise to extend an edit operation asynchronously.
I’m using editDocument. Is there something else I’m missing?