I’m having a problem adding artboards from the plugin when there are elements already in the document/pasteboard.
For example if there is a text I can’t add an artboard from the plugin.
const addArtboard = () => {
let btns = document.querySelectorAll("button");
const getValues = (event) => {
let activeBtn = event.currentTarget;
let name = activeBtn.getAttribute("data-name");
let fname = activeBtn.getAttribute("data-fname");
let width = activeBtn.getAttribute("data-width");
let height = activeBtn.getAttribute("data-height");
editDocument({ editLabel: "add artboard" }, (selection, documentRoot) => {
let newArtboard = new Artboard();
newArtboard.height = JSON.parse(height);
newArtboard.width = JSON.parse(width);
newArtboard.fill = new Color("#ffffff");
newArtboard.name = name;
newArtboard.fname = fname;
documentRoot.addChild(newArtboard);
});
};
for (let i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", getValues);
}
};