-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathCopy Layer as SVG.sketchplugin
34 lines (30 loc) · 1.15 KB
/
Copy Layer as SVG.sketchplugin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copy to SVG
// This plugin copies the selected object to the clipboard, as SVG
function make_temp_folder(){
var guid = [[NSProcessInfo processInfo] globallyUniqueString]
var path = tmp_path + guid
[[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:true attributes:nil error:nil]
export_path = path
}
function copy_text(txt){
var pasteBoard = [NSPasteboard generalPasteboard]
[pasteBoard declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil]
[pasteBoard setString:txt forType:NSPasteboardTypeString]
}
function do_export(){
log("do_export")
var slice = [BCRect rectWithRect:rect];
[doc saveArtboardOrSlice:slice toFile:export_filename];
var file_url = [NSURL fileURLWithPath:export_filename]
var str = [[NSString alloc] initWithContentsOfURL:file_url]
copy_text(str)
[doc showMessage:"SVG Path copied to clipboard"]
}
var sel = context.selection[0],
doc = context.document,
rect = [sel absoluteInfluenceRect],
tmp_path = "/tmp/com.bomberstudios.sketch-commands/",
export_path;
make_temp_folder()
var export_filename = export_path + "/" + [sel name] + ".svg";
do_export()