Prevent Artboards from overlapping when adding to the document

Not sure what to reference here, but I know there’s something in the API that I can use to prevent artboards from overlapping another artboard when it’s added to the document?

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.width +'X'+ newArtboard.height;
  documentRoot.addChild(newArtboard);
});

Right now I’m just using .addChild() but is there something else that I can use to ensure the artboards aren’t overlapping another artboard when they’re added to the document?

Thanks in advanced,
Kenny

Since XD gives you complete freedom here, it’s up to you to find free space in the global coordinate systems.

It’s somewhat tedious, but easy enough, to scan all artboards in the document, and build a data structure that describes the occupied space on the canvas, then use that to place somewhere unoccupied.

I can appreciate the need, however, for some kind of convenience function, like “find me the rightmost/leftmost/topmost/bottommost artboard where I can place another next to it”.

1 Like

This feels like something that would be a good contribution to the plugin toolkit repo – if someone built it out :slight_smile: