I’m getting the following error when I try to set the pluginData property:
Plugin Error: Plugin xyz is not permitted to make changes from the background. Return a Promise to continue execution asynchronously.
at convertPluginErrorToString (plugins/PluginErrorUtil.js:1:198)
at internalFormatPluginError (plugins/PluginErrorUtil.js:1:503)
at internalReportPluginError (plugins/PluginErrorUtil.js:1:610)
at Object.reportPluginError (plugins/PluginErrorUtil.js:1:1042)
at Object.checkAllowedToEdit (plugins/ScenegraphGuard.js:1:1178)
at Artboard.<anonymous> (plugins/ScenegraphWrappers.js:1:11133)
at setElementPluginData (/Users/user/Library/Application Support/Adobe/Adobe XD CC/develop/plugin/main.js:2556:23)
I know it’s outside of the edit context so I’ve placed a try catch around it but it’s still showing up in the console.
Example code:
try {
// get an instance to a non selected artboard and set it's pluginData property
artboard.pluginData = JSON.stringify({x:10,y:20});
}
catch(error) {
// nothing here
}
Related question. Is there a way to check if a sceneNode is in an editable context?
Plugin xyz is not permitted to make changes from the background (in my experience) doesn’t have anything to do with the edit context, but with handling asynchronous code.
While I agree that the error probably shouldn’t show up when the code is in a try/catch block, this probably is unrelated to the edit context (are you sure you’re handling asynchronous bits of the code correctly?).
To store general metadata for the document overall, set pluginData on the rootnode of the scenegraph. Metadata on the root node can be changed from anyedit context.
So that states the root node is settable from any context but what about the nodes that are not the root node?
If you’ll also notice the call stack shows the Object.checkAllowedToEdit
at Object.checkAllowedToEdit (plugins/ScenegraphGuard.js:1:1178)
at Artboard.<anonymous> (plugins/ScenegraphWrappers.js:1:11133)
I’m not making the case to change it but I can’t see any strong arguments why pluginData needs an edit context if you can set the root node plugin data and if plugin data only affects the current plugin.
Here’s another thing. The code above is looping through all of the artboards. The focused artboard does not throw an error but the other artboards do. So is that async or edit context?
Ok – that really is strange. If I remember correctly, edit context errors look different – that might be a “deeper” bug than I’d thought it would be (unfitting error messages definitely sound rather strange ) – do you do something asynchronous in the plugin (i.e. could it be a problem with the async stuff)?
Couldn’t you just use group.children.includes(myNode) for that? Since that’s ES2016, I don’t know if it’s supported by XD, but otherwise, the more legacy group.children.indexOf(myNode) != -1 should also work…
According to the documentation, that is to be expected as long as you haven’t selected a node inside a group (although I don’t really see the logic behind that ) :
If the user hasn’t drilled into any container node, this value is the document root, and its scope includes all immediate children of the pasteboard (including Artboards), and all immediate children of all those Artboards.
– selection · Adobe XD Plugin Reference
You’re probably better off using the “plain” selection…
yes while selecting an scenenode gives access to its linear mates means artboard selection gives access to other artboards and their children this is because atleast selection for a document is artboard to qualify it to be a selection
The second command function “showMainDialogWithOptions()” calls the first function but passes a parameter to the first command function. In showMainDialogWithOptions() the line where I called the first function, “showMainDialog()” did not have the await keyword before hand: