Error creating rendition for a group

Hello

Using this function

async function exportRendition(myParentFolder, selection) {
    let scenegraph = require("scenegraph");
    const application = require("application");
    const rectangles = scenegraph.root.children.filter(node => node instanceof scenegraph.Rectangle);
    const groups = scenegraph.root.children.filter(node => node instanceof scenegraph.Group);
    if (rectangles.length > 0) {
        var children = rectangles;
        if (groups.length > 0)
            children = rectangles.concat(groups);
    }

    console.log(children);

    try {
        const arr = children.map(async item => {
            if (item instanceof Rectangle) {
                //selection.items = [item];
                console.log(`${item.name}.png`);
                const file = await myParentFolder.createFile(`${item.name}.png`);
                let obj = {};
                obj.node = item //selection.items[0]
                obj.outputFile = file;
                obj.type = "png";
                obj.scale = 1;
                return obj
            }
        })
        console.log(arr.length);
        const renditions = await Promise.all(arr);
        await application.createRenditions(renditions);
    } catch (err) {
        console.log(err);
    }
}

gives me the error :
[Error: Expected ‘node’ field with a SceneNode value]

This error is happening when it tries to export the first Group item!

Can anyone help?

1 Like

I’ve allowed myself to give your code some formatting so it’s easier for us to read, understand and help :wink:. I hope you don’t mind…

For future reference: Posts gets formatted as Markdown, so that you can format a block of code like this:

image

resulting in something like this:

// my code

This makes the code easily readable and everyone much more willing to help :slightly_smiling_face:

Thanks! :slight_smile:

1 Like

Could you do a console.log(JSON.stringify(renditions)) before the await application.createRenditions(renditions) and post the output here?

Thank you very much in advance :+1:

Hello @pklaschka

Thank’s for your help!

The result is this:

[{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},{"node":{"_childrenList":{}},"outputFile":{},"type":"png","scale":1},null,null,null,null]
1 Like

The nulls are from the following objetcs:

  Group ('NavigateInto') {
    width: 54.08, height: 54.08
    global X,Y: 278, -148
    parent: RootNode
    children: [Ellipse, BooleanGroup]
  },
  Group ('DropDown') {
    width: 54.08, height: 54.08
    global X,Y: 358.95, -146.08
    parent: RootNode
    children: [Ellipse, BooleanGroup]
  },
  Group ('EditButton') {
    width: 54.08, height: 54.08
    global X,Y: 431.75, -146.08
    parent: RootNode
    children: [Ellipse, BooleanGroup]
  },
  Group ('Syslog') {
    width: 305.38, height: 122.15
    global X,Y: 298, -337
    parent: RootNode
    children: [Group]
  } ]

That most certainly is interesting. I’ll have a closer look (including testing the code myself) when I get home. Without testing, I (after 20 minutes of “manually processing” the code, i.e., simulating the APIs or my knowledge thereof with my brain :rofl: ) don’t see anything wrong with it…

1 Like

Yeah! Thanks! U’r right, it is strange, humm…Well meanwhile is time to move on to export components!

Thanks

1 Like

It’s was a bug in the code lol…sorry!

Putting null entries in your renditions array will give this error message – every renditions request must be a valid rendition options object. In your example you can fix this by doing something like:

renditions = renditions.filter(item => item); // remove null entries

Also, please note that item.name won’t always be a string that is a valid filename, so you’ll probably want to do some filtering there or else your plugin will fail sometimes. For example, designers can put * or / in layer names in XD.

Thank you for the feedback @peterflynn!

1 Like