root.pluginData undefined when running plugin again


#1

I want to store the results of a dialog into the root node so I can set the defaults of the dialog the next time the dialog shows.

Setting works:

      // write dialog results into document root
      const { selection, root } = require("scenegraph")
      root.pluginData = results
      console.log(root.pluginData);

as I see the log output showing the plugin data. results is an object.

Reading does not work:
When running the script again, I attempt to read the plugindata.

  // attempt to read previous settings in document root
  const { selection, root } = require("scenegraph")
  console.log(root.pluginData);

There is no error in the console. The log output is undefined.

Setting and Getting is all done in async functions.


#2

Hi @johannes,

selection and root are two parameters of your main function rather than classes of the scenegraph module (reference: selection documentation).

Try this code in your plugin:

function myPluginCommand(selection, root) {
    const results = {
        "a": "b"
    }
    root.pluginData = results
    console.log(root.pluginData);
}

Hope this helps!


#3

@stevekwak

Since XD 14, they should also be exported members of the scenegraph module (cf. https://adobexdplatform.com/plugin-docs/reference/scenegraph.html#other-module-members) :wink:


#4

@pklaschka - thanks for catching that - I’m still catching up from the year end break :slight_smile:

However, I’m still unable to replicate the error @johannes mentioned above and able to access the pluginData property of root after saving some data. Please let me know if anyone else is able to replicate the error


#5

I’m not able to test this right now, but here are a few ideas on what could possibly cause this (@johannes):

  • Was it a saved document? Although that shouldn’t really make a difference, since the pluginData is document-specific, a bug with unsaved documents seems at least possible (or even kind of likely)
  • (Potentially stupid question, but just to make sure): Was XD 14.x used for this? The behavior that got described would match the behavior that would occur when testing it in XD 13 (however, testing in XD 13 would probably have led to an error in the console about trying to access member pluginData of undefined since root then would really – as stated by @stevekwak – only exist as a parameter and not as an exported module of the scenegraph).
  • (Again, a potentially stupid question, but I really want to make sure :wink:): Was the document closed and reopened (or in any other way changed) between the two sections of code?

As I’ve stated, I can’t try to replicate this now, but hopefully, we may get closer by continuing on from here :wink:

Hope this helps,
Pablo


#6

@johannes - a good first thing to check would be to look at the console output, Plugins > Development > Developer Console. Are any error messages listed there? If your plugin threw an error or otherwise misbehaved, XD reverts any changes it made during that command – which would include any changes to pluginData you made.