From 800db322de9676005a2788d2d991c94a3b99c5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=20Mu=C3=B1oz?= Date: Sat, 8 Aug 2015 12:21:03 +0200 Subject: [PATCH] A plugin for @mdo : ) --- Paste As New Artboard.sketchplugin | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Paste As New Artboard.sketchplugin diff --git a/Paste As New Artboard.sketchplugin b/Paste As New Artboard.sketchplugin new file mode 100644 index 0000000..6117b9f --- /dev/null +++ b/Paste As New Artboard.sketchplugin @@ -0,0 +1,28 @@ +// Paste as new Artboard +// Takes whatever is on the clipboard, pastes it, and makes a new Artboard around it + +var doc = context.document, + page = doc.currentPage(), + artboardName = "Pasted from Clipboard" + +// If you want to be asked for the artboard name before pasting it, uncomment the following line +// artboardName = [doc askForUserInput:"New artboard name" initialValue:""] + +[NSApp sendAction:"paste:" to:nil from:doc] + +var pastedRect = sumOfRects(page.selectedLayers()) + +var artboard = MSArtboardGroup.alloc().initWithFrame(pastedRect) +artboard.name = artboardName +page.addLayers([artboard]) +[page moveLayersToArtboards] +[artboard select:true byExpandingSelection:false] + +function sumOfRects(layers){ + var result = [[layers firstObject] rect]; + var count = [layers count]; + for (var i=1; i