Skip to content

Commit

Permalink
A plugin for @mdo : )
Browse files Browse the repository at this point in the history
  • Loading branch information
bomberstudios committed Aug 8, 2015
1 parent f7e8a98 commit 800db32
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Paste As New Artboard.sketchplugin
Original file line number Diff line number Diff line change
@@ -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<count; i++) {
result = NSUnionRect(result, layers.objectAtIndex(i).rect())
}
return result
}

0 comments on commit 800db32

Please sign in to comment.