diff --git a/.appcast.xml b/.appcast.xml index aa9363f..236f73d 100644 --- a/.appcast.xml +++ b/.appcast.xml @@ -5,4 +5,4 @@ - \ No newline at end of file + diff --git a/QuickStyles.sketchplugin.zip b/QuickStyles.sketchplugin.zip index e74189e..3fcadbc 100644 Binary files a/QuickStyles.sketchplugin.zip and b/QuickStyles.sketchplugin.zip differ diff --git a/QuickStyles.sketchplugin/Contents/Sketch/my-command.js b/QuickStyles.sketchplugin/Contents/Sketch/my-command.js index 4dfa4cf..619c091 100644 --- a/QuickStyles.sketchplugin/Contents/Sketch/my-command.js +++ b/QuickStyles.sketchplugin/Contents/Sketch/my-command.js @@ -348,67 +348,78 @@ module.exports = function toArray(object) { /* WEBPACK VAR INJECTION */(function(console) {sketch = context.api(); doc = context.document; -sel = context.selection; currentPage = doc.currentPage(); font = []; colours = []; function addArtboard(page, name) { - var artboard = MSArtboardGroup["new"](); - frame = artboard.frame(); - frame.setWidth(4000); - frame.setHeight(4000); - frame.setConstrainProportions(false); - page.addLayers([artboard]); - artboard.setName(name); - return artboard; + var artboard = MSArtboardGroup["new"](); + frame = artboard.frame(); + frame.setWidth(4000); + frame.setHeight(4000); + frame.setConstrainProportions(false); + page.addLayers([artboard]); + artboard.setName(name); + return artboard; } -if (sel == 0) { - doc.showMessage('You need to select some text and colours!'); +if (context.api().selectedDocument.selectedLayers.length == 0) { + context.document.showMessage('You need to select some text and colours!'); } else { - var addTextLayer = function addTextLayer(target, label, font, colour, i, j) { - var textLayer = MSTextLayer["new"](); - console.log(textLayer); - textLayer.setStringValue("Example text, im a pretty unicorn"); - textLayer.setName(label); - textLayer.setFont(font); - textLayer.setTextColor(colour); - textLayer.setTextBehaviour(1); - textLayer.absoluteRect().setWidth(500); - textLayer.absoluteRect().setHeight(200); - textLayer.absoluteRect().setRulerX(i * 600); - textLayer.absoluteRect().setRulerY(j * (textLayer.frame().height() + 50)); - target.addLayers([textLayer]); - return textLayer; - }; - - var board = new addArtboard(currentPage, "Quick Text Styles"); - - ; - - context.api().selectedDocument.selectedLayers.iterate(function (layer) { - - if (layer['_object'].isKindOfClass(MSTextLayer)) { - font.push({ - "font": layer['_object'].font(), - "text": layer['_object'].name() - }); - } - if (layer['_object'].isKindOfClass(MSShapeGroup)) { - colours.push({ - "colour": layer['_object'].style().fills()[0].color(), - "name": layer['_object'].name() - }); - } - }); - - for (var i = 0; i < colours.length; i++) { - for (var j = 0; j < font.length; j++) { - addTextLayer(board, font[j].text + "/" + colours[i].name, font[j].font, colours[i].colour, i, j); - } + var addTextLayer = function addTextLayer(target, label, font, colour, i, j) { + var textLayer = MSTextLayer["new"](); + console.log(textLayer); + textLayer.setStringValue("Example text, im a pretty unicorn"); + textLayer.setName(label); + textLayer.setFont(font); + textLayer.setTextColor(colour); + textLayer.setTextBehaviour(1); + textLayer.absoluteRect().setWidth(500); + textLayer.absoluteRect().setHeight(200); + textLayer.absoluteRect().setRulerX(i * 600); + textLayer.absoluteRect().setRulerY(j * (textLayer.frame().height() + 50)); + target.addLayers([textLayer]); + return textLayer; + }; + + var board = new addArtboard(currentPage, "Quick Text Styles"); + + ; + + context.api().selectedDocument.selectedLayers.iterate(function (layer) { + + //If the selection contains groups, this **should** loop through them, hopefully. + + if (layer['_object'].isKindOfClass(MSLayerGroup)) { + for (var child = 0; child < layer['_object'].children().length; child++) { + + pushLayer(layer['_object'].children()[child]); + } + } else pushLayer(layer['_object']); + + function pushLayer(l) { + + if (l.isKindOfClass(MSTextLayer)) { + font.push({ + "font": l.font(), + "text": l.name() + }); + } + if (l.isKindOfClass(MSShapeGroup)) { + colours.push({ + "colour": l.style().fills()[0].color(), + "name": l.name() + }); + } + } + }); + + for (var i = 0; i < colours.length; i++) { + for (var j = 0; j < font.length; j++) { + addTextLayer(board, font[j].text + "/" + colours[i].name, font[j].font, colours[i].colour, i, j); } - board.resizeToFitChildren(); + } + board.resizeToFitChildren(); } //end of else /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0))) diff --git a/src/my-command.js b/src/my-command.js index 7f49046..c3dce1b 100644 --- a/src/my-command.js +++ b/src/my-command.js @@ -1,6 +1,5 @@ sketch = context.api() doc = context.document; -sel = context.selection; currentPage = doc.currentPage(); font = []; colours = []; @@ -16,7 +15,7 @@ function addArtboard(page, name) { return artboard; } -if(sel == 0){doc.showMessage('You need to select some text and colours!')} +if(context.api().selectedDocument.selectedLayers.length == 0){context.document.showMessage('You need to select some text and colours!')} else{ var board = new addArtboard(currentPage, "Quick Text Styles") @@ -36,20 +35,38 @@ function addTextLayer (target, label, font, colour,i, j) { return textLayer; }; + + context.api().selectedDocument.selectedLayers.iterate(layer => { -if(layer['_object'].isKindOfClass(MSTextLayer)){ - font.push({ - "font": layer['_object'].font(), - "text": layer['_object'].name(), - } - )} -if(layer['_object'].isKindOfClass(MSShapeGroup)){ + + //If the selection contains groups, this **should** loop through them, hopefully. + +if(layer['_object'].isKindOfClass(MSLayerGroup)){ + for(var child = 0; child < layer['_object'].children().length; child++){ + + pushLayer(layer['_object'].children()[child]) + } +} +else(pushLayer(layer['_object'])) + + +function pushLayer(l){ + +if(l.isKindOfClass(MSTextLayer)){ + font.push({ + "font": l.font(), + "text": l.name(), +}) +} +if(l.isKindOfClass(MSShapeGroup)){ colours.push({ - "colour":layer['_object'].style().fills()[0].color(), - "name":layer['_object'].name(), + "colour":l.style().fills()[0].color(), + "name":l.name(), } )} +} + }) for(var i = 0; i < colours.length; i++){ @@ -57,5 +74,4 @@ for(var j = 0; j < font.length; j++){ addTextLayer(board, font[j].text + "/" + colours[i].name, font[j].font, colours[i].colour, i, j) }} board.resizeToFitChildren(); - } //end of else