typeof(scenegraph.SceneNode) is undefined

By some reason SceneNode is undefined:

console.log("scenegraph.Artboard", typeof(scenegraph.Artboard));
console.log("scenegraph.SceneNode", typeof(scenegraph.SceneNode));
console.log("scenegraph.GraphicNode", typeof(scenegraph.GraphicNode));

output:

scenegraph.Artboard function
scenegraph.SceneNode undefined
scenegraph.GraphicNode function

According to https://adobexdplatform.com/plugin-docs/reference/scenegraph.html#SceneNode it must be a class.

Can you create a raw SceneNode? (Doubt it.)

If not, then that’s why it’s not defined.

Really you can’t create instance of the GraphNode either as it’s abstract class. Creating new instance is not the only possible way of using classes. In my case I need to check if tree node is a scene node instance:

if (value instanceof scenegraph.SceneNode) {
}

If you have a node, it has to be a SceneNode descendent class of some sort. (IIUC)

It is interesting that GraphicNode has a creation function.

if you have a node,

That’s what I’m trying to check with instanceof

But if you got a node from dealing with the scenegraph in any way, it’s a SceneNode, no?

Here’s what I’m talking about Serialize scenegraph data to JSON?

Right, but you just have to individually pick apart the scenegraph node components, and not rely on general Object conversion.

That’s what I do in my version of scenegraph-to-json.

Manual mapping is not very good idea as you have to change the flow on every update of input data (format modification). As it’s changing every month or another such idea looks very unstable.
But my question was not about how to map the json. It’s about the point that in documentation SceneNode is an abstract class but typeof(SceneNode) returns undefined which is not correct.

OK, then you should probably just ask for an API improvement whereby scenegraph nodes can be safely and automatically converted to JSON.

The same issue exists for File and Folder “classes” in the uxp.storage namespace.

It’s entirely natural to try:

const UXPFile = require("uxp").storage.File;
if (fileOrFolder instanceof UXPFile)
    // ...

But we are currently barred from doing so because

require("uxp").storage.File === undefined

The parent “class” of both File and Folder (Entry) has isFolder and isFile properties… but they seem incredibly redundant… why not just provide the class function and throw an error if someone tries to use the class constructor to instantiate something when you don’t want them to…?

2 Likes