-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathSet Export Sizes.sketchplugin
57 lines (49 loc) · 1.26 KB
/
Set Export Sizes.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Add Slice Sizes for Selected Layer
// Customize these with your desired formats & scales
var export_presets = [
{
"format": "png",
"scale": 1,
"suffix": ""
},
{
"format": "png",
"scale": 2,
"suffix": "@2x"
},
{
"format": "svg",
"scale": 1,
"suffix": ""
},
{
"format": "pdf",
"scale": 3,
"suffix": "-wireframe"
}
]
// Loop through selected layers:
var selection = context.selection
var original_selection = []
for (var i=0; i < selection.count(); i++) {
var layer = selection.objectAtIndex(i),
export_options = layer.exportOptions(),
export_formats = export_options.exportFormats()
original_selection.push(layer)
// Clear all exportable sizes
export_options.removeAllExportFormats()
for (var s = 0; s < export_presets.length; s++) {
var preset_data = export_presets[s]
var format = layer.exportOptions().addExportFormat()
format.fileFormat = preset_data.format
format.scale = preset_data.scale
format.name = preset_data.suffix
}
}
// Restore original selection
context.document.currentPage().deselectAllLayers()
for (var j=0; j < original_selection.length; j++) {
var l = original_selection[j]
[l select:true byExpandingSelection:true]
}
context.document.reloadInspector()