├── README.md ├── SymbolMe.sketchplugin └── Contents │ └── Sketch │ ├── manifest.json │ └── script.cocoascript └── demo.gif /README.md: -------------------------------------------------------------------------------- 1 | # Symbol me 2 | 3 | This plug-in will convert the select layer to a symbol and updates all the other 4 | layers with same styles and same layers with symbol just created. 5 | 6 | This is really helpful when you want to covert a bunch of scattered (nested deep down and its painful to select all of them one by one) layers to symbols. 7 | 8 | ![](https://github.com/websiddu/sketch-symbol-me/blob/master/demo.gif?raw=true) 9 | 10 | 11 | # Usage 12 | 13 | Select a layer that you want to convert to symbol and press `Command + Shift + U` this automatically finds all the layers with the same name and updates them with the newly created symbol. 14 | 15 | Watch the demo [https://vimeo.com/151220931](https://vimeo.com/151220931) 16 | 17 | # Download & Install Manually 18 | 19 | Download from [Github](https://github.com/websiddu/sketch-symbol-me/archive/master.zip) 20 | 21 | Two ways to install: 22 | 23 | Option 1: 24 | Open SymbolMe.sketchplugin and Sketch will ask if you'd like it installed 25 | 26 | Option 2: 27 | While Sketch 3 is open, go to Plugins -> Reveal Plugins Folder, and place SymbolMe.sketchplugin there. 28 | 29 | # Changelog 30 | 31 | v 1.1.1 32 | - Coverts the layer groups to symbols based on style and matches 33 | 34 | v 1.1.0 35 | - Convers layer groups to symbols based on the name of the layer 36 | 37 | 38 | # License 39 | It's free for whatever use ( commercial or personal ), both for web or for printing purpose. Licensed under MIT. 40 | -------------------------------------------------------------------------------- /SymbolMe.sketchplugin/Contents/Sketch/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "author" : "Siddhartha Gudipati", 3 | "commands" : [ 4 | { 5 | "script" : "script.cocoascript", 6 | "handler" : "createSymbol", 7 | "shortcut" : "shift command u", 8 | "name" : "Update with Symbol", 9 | "identifier" : "createsymbol" 10 | } 11 | ], 12 | "menu": { 13 | "isRoot": true, 14 | "items": [ 15 | "createsymbol" 16 | ] 17 | }, 18 | "identifier" : "com.websiddu.sketch-symbol-me", 19 | "version" : "1.1.1", 20 | "description" : "Create symbols from same named layer groups.", 21 | "name" : "Update with symbol" 22 | } 23 | -------------------------------------------------------------------------------- /SymbolMe.sketchplugin/Contents/Sketch/script.cocoascript: -------------------------------------------------------------------------------- 1 | // Display an error alert 2 | function alert(msg, title) { 3 | title = title || "alert" 4 | var app = [NSApplication sharedApplication] 5 | [app displayDialog:msg withTitle:title] 6 | } 7 | 8 | // Display an error alert and exit 9 | function exitWithAlert(message, title) { 10 | // alert(message, title) 11 | throw(nil) // exit the plugin 12 | } 13 | 14 | var createSymbol = function(context) { 15 | try { 16 | // Begin validation of selection 17 | 18 | // Ensure at least one layer is selected 19 | var selection = context.selection 20 | // Ensure at least one layer is selected 21 | if ([selection count] < 1) { 22 | exitWithAlert('Select at least one layer to create a symbol.', 'Select Layer(s)') 23 | } 24 | 25 | var layer = [selection objectAtIndex:0] 26 | 27 | // Layer is already a symbol 28 | if (layer.isSymbol()) { 29 | exitWithAlert('This layer is already a symbol.', 'Already Symbol') 30 | } 31 | 32 | var doc = context.document 33 | var page = [doc currentPage]; 34 | var layers = [page children]; 35 | 36 | 37 | var symbols = doc.documentData().layerSymbols() 38 | 39 | if (layer instanceof MSLayerGroup) { // Layer is already a group 40 | 41 | // Add group to symbols 42 | var predicate = [NSPredicate predicateWithFormat:@"(FUNCTION(self, 'isEqualForSync:asPartOfSymbol:', %@, nil) == YES)", [selection objectAtIndex:0]] 43 | var selectedLayers = [layers filteredArrayUsingPredicate:predicate]; 44 | 45 | var symbol = symbols.addSymbolWithName_firstInstance(layer.name(), layer) 46 | var count = 0 47 | 48 | for(var i = 0; i < [selectedLayers count]; i++) { 49 | symbol.registerInstance(selectedLayers.objectAtIndex(i)); 50 | selectedLayers.objectAtIndex(i).setName(symbol.name()); 51 | count = count + 1; 52 | } 53 | 54 | doc.showMessage("Converted " + count + " layers to symbols.") 55 | 56 | // Toggle selection to refresh UI 57 | layer.setIsSelected(false) 58 | layer.setIsSelected(true) 59 | 60 | } 61 | 62 | } catch(e) { 63 | log(e) 64 | } 65 | }; 66 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/websiddu/sketch-symbol-me/4bc0b5d38622f1195209267bc480cf554e6fac50/demo.gif --------------------------------------------------------------------------------