-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f7e8a98
commit 800db32
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |