How do I require scenegraph?

When I run the following code, I get “scenenode is not defined”. I think that error is correct but I’m not sure how to include/require the scenegraph class itself. Any tips?

const {Rectangle, Color, Text} = require("scenegraph"); 

function stringTagger(selection) {
    let guid = selection.items[0].guid;
    let textValue = selection.items[0].text;

    console.log("Items Selected: ", selection.items);
    console.log("GUID of 1st item: ", guid);

    let sameGuid = scenegraph.getNodeByGUID(guid);
    if (sameGuid) {
        // sameGuid.text = "Copy from the CMS"
        console.log("Text value of 1st item: ", textValue)


module.exports = {
    commands: {
        tagString: stringTagger,
1 Like


const scenegraph = require('scenegraph')
const { Rectangle, Color, Text } = scenegraph


1 Like

Thanks @cpryland, that gets me further along but not quite there. The error I receive now states: “scenegraph.getNodeByGUID is not a function”. I’m referencing the docs on getNodeByGUID and appear to be using it correctly. I haven’t found any working examples of this function anywhere. @pklaschka, do you have any insights?

1 Like

I just ran the code you posted and get the following console output, which, as far as I can see, is the expected one :thinking:

Items Selected:  [ Text ('fwef') {
    width: 337, height: 172
    global X,Y: 736, 473
    parent: Artboard ('Web 1920 – 1')
    fill: ff707070
  } ]
GUID of 1st item:  9a8059a5-2b89-4e19-a7ba-80e767cfece5
Text value of 1st item:  fwef

Therefore (as long as I understand what the code is supposed to do correctly), the issue doesn’t appear to be with your code. What version of XD are you using? Also, if you’re using the typings, I unfortunately haven’t gotten to update those yet, meaning that if you have some sort of compilation step (typescript or stuff like that), you’ll have to let it ignore the “undefined” getNodeByGUID somehow…

1 Like

As @pklaschka notes, you’re probably not running the latest XD (28), which added the getNodeByGUID method.


Thank you @pklaschka and @cpryland! I made the ill-informed mistake of thinking I had version 28 because my Creative Cloud status reported being the latest version.

I’ve added that to my manifest file to prevent the same mistake.

 "host" : {
    "app" : "XD",
    "minVersion" : "28.0"