├── README.md ├── SketchDivide.sketchplugin └── Contents │ └── Sketch │ ├── divide.js │ ├── manifest.json │ └── pencil_split.js └── images ├── divide.png └── pencil_split.png /README.md: -------------------------------------------------------------------------------- 1 | Divide Sketch Plugin 2 | ============= 3 | 4 | ### [DEPRECATED] This plugin doesn't support latest versions of Sketch and will not be maintained anymore 5 | 6 | Plugins for [Sketch](https://www.sketchapp.com/) app 7 | 8 | These plugins are for splitting shapes as shown in examples below. 9 | 10 | #### **Update** 11 | 12 | - Plugin got support of Sketch 4.0 13 | - Pencil split is not available anymore. Besides that, Divide plugin has limited functionality. Just remember that Sketch cannot flatten shapes into multiple paths. 14 | 15 | ![Divide](images/divide.png) 16 | 17 | ![PencilSplit](images/pencil_split.png) 18 | -------------------------------------------------------------------------------- /SketchDivide.sketchplugin/Contents/Sketch/divide.js: -------------------------------------------------------------------------------- 1 | 2 | function onRun(context) { 3 | if(context.selection.count() != 2) { 4 | print("Selection is wrong"); 5 | return; 6 | } 7 | var shape1 = context.selection[0]; 8 | var shape2 = context.selection[1]; 9 | var shape1_copy = [shape1 duplicate]; 10 | var shape2_copy = [shape2 duplicate]; 11 | var shape1_second_copy = [shape1_copy duplicate]; 12 | var shape2_second_copy = [shape2_copy duplicate]; 13 | 14 | var app = NSApplication.sharedApplication(); 15 | var call_action = function(menuitem) { 16 | var action = menuitem.action(); 17 | print(action); 18 | var target = app.targetForAction(action); 19 | print(target); 20 | 21 | var method_signature = [[target class] instanceMethodSignatureForSelector: action]; 22 | var invocation = [NSInvocation invocationWithMethodSignature: method_signature]; 23 | [invocation setTarget:target]; 24 | [invocation setSelector: action]; 25 | [invocation invoke]; 26 | }; 27 | var main_menu = app.mainMenu(); 28 | var layer_menu = main_menu.itemWithTitle("Layer").submenu(); 29 | var arrange_menu = main_menu.itemWithTitle("Arrange").submenu(); //[0] - bring forward 30 | var combine_menu = layer_menu.itemWithTitle("Combine").submenu(); 31 | var paths_menu = layer_menu.itemWithTitle("Paths").submenu(); 32 | 33 | var intersect = function() { call_action(combine_menu.itemWithTitle("Intersect")); }; 34 | var subtract = function() { call_action(combine_menu.itemWithTitle("Subtract")); }; 35 | var flatten = function() { call_action(paths_menu.itemWithTitle("Flatten")); }; 36 | var move_to_front = function() { call_action(arrange_menu.itemWithTitle("Move To Front")); }; 37 | 38 | 39 | [shape1 select:true byExpandingSelection:false]; 40 | [shape2 select:true byExpandingSelection:true]; 41 | intersect(); 42 | flatten(); 43 | 44 | [shape1_second_copy select:true byExpandingSelection:false]; 45 | move_to_front(); 46 | 47 | [shape2_second_copy select:true byExpandingSelection:false]; 48 | move_to_front(); 49 | 50 | [shape1_copy select:true byExpandingSelection:false]; 51 | [shape2_second_copy select:true byExpandingSelection:true]; 52 | subtract(); 53 | flatten(); 54 | 55 | [shape1_second_copy select:true byExpandingSelection:false]; 56 | [shape2_copy select:true byExpandingSelection:true]; 57 | subtract(); 58 | flatten(); 59 | 60 | var doc = context.document 61 | [[doc currentPage] deselectAllLayers]; 62 | }; -------------------------------------------------------------------------------- /SketchDivide.sketchplugin/Contents/Sketch/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "Divide", 3 | "identifier" : "pw.accky.sketch.splitdivide", 4 | "version" : "1.0", 5 | "description" : "Simple plugin for splitting shapes.", 6 | "authorEmail" : "konstantin@accky.pw", 7 | "author" : "Konstantin Raspopov", 8 | "commands" : [ 9 | { 10 | "script" : "divide.js", 11 | "handler" : "onRun", 12 | "shortcut" : "control z", 13 | "name" : "Divide", 14 | "identifier" : "divide" 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /SketchDivide.sketchplugin/Contents/Sketch/pencil_split.js: -------------------------------------------------------------------------------- 1 | // currently unused 2 | 3 | function onRun(context) { 4 | if(context.selection.count() != 2) { 5 | print("Selection is wrong"); 6 | return; 7 | } 8 | 9 | var app = NSApplication.sharedApplication(); 10 | var call_action = function(menuitem) { 11 | var action = menuitem.action(); 12 | print(action); 13 | var target = app.targetForAction(action); 14 | print(target); 15 | 16 | var method_signature = [[target class] instanceMethodSignatureForSelector: action]; 17 | var invocation = [NSInvocation invocationWithMethodSignature: method_signature]; 18 | [invocation setTarget:target]; 19 | [invocation setSelector: action]; 20 | [invocation invoke]; 21 | }; 22 | 23 | var main_menu = app.mainMenu(); 24 | var layer_menu = main_menu.itemWithTitle("Layer").submenu(); 25 | var combine_menu = layer_menu.itemWithTitle("Combine").submenu(); 26 | var paths_menu = layer_menu.itemWithTitle("Paths").submenu(); 27 | 28 | var subtract = function() { call_action(combine_menu.itemWithTitle("Subtract")); }; 29 | var flatten = function() { call_action(paths_menu.itemWithTitle("Flatten")); }; 30 | var split = function() { call_action(paths_menu.itemWithTitle("Split")); }; 31 | var convert_to_outlines = function() { call_action(layer_menu.itemWithTitle("Convert to Outlines")); }; 32 | 33 | var the_shape = context.selection[0]; // selection is always bottom to top layers 34 | [the_shape select:false byExpandingSelection:true]; 35 | 36 | convert_to_outlines(); 37 | 38 | [the_shape select:true byExpandingSelection:true]; 39 | 40 | subtract(); 41 | flatten(); 42 | split(); 43 | 44 | var doc = context.document 45 | [[doc currentPage] deselectAllLayers]; 46 | }; -------------------------------------------------------------------------------- /images/divide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KrevedAccky/SketchSplitDivide/1b6a4c90b4c50229ba6cdf8d31e300d068c6ead9/images/divide.png -------------------------------------------------------------------------------- /images/pencil_split.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KrevedAccky/SketchSplitDivide/1b6a4c90b4c50229ba6cdf8d31e300d068c6ead9/images/pencil_split.png --------------------------------------------------------------------------------