Skip to content

Instantly share code, notes, and snippets.

@bomberstudios
Last active July 8, 2016 12:27
Show Gist options
  • Save bomberstudios/3fee7b1079b51743cfdd to your computer and use it in GitHub Desktop.
Save bomberstudios/3fee7b1079b51743cfdd to your computer and use it in GitHub Desktop.
Add @3x resolution to existing Sketch documents
// This plugin will add a @3x size to all existing slices and exportable layers,
// that already have a @1x and @2x size
var p = [doc pages]
for (var i = 0; i < [p count]; i++) {
var current_page = [p objectAtIndex:i]
var exportable_layers = [current_page exportableLayers]
for (var l = 0; l < [exportable_layers count]; l++) {
var slice_or_layer = [exportable_layers objectAtIndex:l]
if ([slice_or_layer exportOptions]) {
var has1x = false,
has2x = false,
has3x = false
var opts = [slice_or_layer exportOptions],
sizes = [opts sizes]
for(var k=0; k < [sizes count]; k++) {
var size = [sizes objectAtIndex:k]
if (size.scale() === 1) {
has1x = true
}
if (size.scale() === 2) {
has2x = true
}
if (size.scale() === 3) {
has3x = true
}
}
if (has1x && has2x && !has3x) {
// Let's add a @3x size
var firstSize = [sizes firstObject]
var newSize = [opts addExportSize]
[newSize setFormat:firstSize.format()]
[newSize setScale:3]
[newSize setName:"@3x"]
}
}
}
}
// This is just a hack to force the updating of the UI to see the new sizes in the inspector
[[doc currentPage] deselectAllLayers]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment