What is Panel plugin edits must be initiated from a supported UI event

@rehdie
From the looks of it, you’re using this as a modal?

application.editDocument is primarily used for panels, while dialogs (by the user interaction of opening the dialog via the plugins menu) already have an “open” slot when you can edit the scenegraph. Instead of using application.editDocument(...), you should be fine by just using it without it (as long as you return a Promise from your function that doesn’t resolve until the dialog is closed (i.e., as long as you need to make edits). As you already have an async function awaiting dialog.showModal(). That should work.

In your use-case, you should therefore be able to use

 button.addEventListener('click', (e) => {
    console.log('button clicked');
    // Do scenegraph manipulation here
});

While it’s probably not impossible to use application.editDocument with modals (in one way or another), it really is meant for persistent panel UIs, where you don’t have this modal-esque timeslot that lasts until the dialog gets closed, but instead have to instantiate such a timeslot (as a result of a user interaction) yourself.

I hope this helps,
Happy Coding,
Pablo

References:

1 Like

What if there was a flag or property that you could check if you’re in an edit context? It would be set behind the scenes.

For example, if you open a modal from the plugin panel then I don’t think you can’t copy to clipboard from the modal because it has to be within a click event and the click event already happened opening the modal. I’ll have to double check though.