How can you to add this Artboard


#1

How can you to add this Artboard.

RootNode Children add Artboard.

In the way below, it does not work.
Am I making a mistake?

function myCommand(selection, documentRoot) {
    let art = new Artboard();
    art.width = 100;
    art.height = 100;
    documentRoot.addChild(art)  
}

#2

Sorry, but is this meant as a question (it’s not quite clear since you used . and not ? which means this could also be meant as a tip on how to add artboards…)?

First of all, you have one obselete closing brace } in line 6 :wink:

Also, you can wrap code in ``` [new line] [your code] [new line] ```. I’ve taken the liberty of formatting it for you :wink:


#3

Thank ynu pklaschka.
updated issue.


#4

If you remove this and (optionally) add a semicolon after documentRoot.addChild(art), it should work.


#5

I fixed it but I could not do it.


#6

Sorry. I forgot that you’ll need to import Artboard from the scenegraph module. Add

const {Artboard} = require('scenegraph');

before the function (resulting in the code below) and it should work (i.e. it does work – I’ve just tested it) :wink:

const {Artboard} = require('scenegraph');

function myCommand(selection, documentRoot) {
   let art = new Artboard();
   art.width = 100;
   art.height = 100;
   documentRoot.addChild(art)  
}