Skip to content

Commit

Permalink
Add group creation command
Browse files Browse the repository at this point in the history
  • Loading branch information
bastienpetit committed Dec 27, 2018
1 parent 49f5306 commit 8eeb58c
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 2 deletions.
184 changes: 184 additions & 0 deletions annotations.sketchplugin/Contents/Sketch/create.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions annotations.sketchplugin/Contents/Sketch/create.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion annotations.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@
"name": "Show",
"identifier": "show",
"script": "show.js"
},
{
"name": "Create 'Annotations' group from selection",
"identifier": "create",
"script": "create.js"
}
],
"menu": {
"title": "Annotations",
"items": [
"hide",
"show"
"show",
"-",
"create"
]
},
"version": "0.3.0",
Expand Down
5 changes: 5 additions & 0 deletions src/commands/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import createAnnotations from "../modules/createAnnotations";

export default function() {
createAnnotations();
}
9 changes: 8 additions & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@
"name": "Show",
"identifier": "show",
"script": "./commands/show.js"
},
{
"name": "Create 'Annotations' group from selection",
"identifier": "create",
"script": "./commands/create.js"
}
],
"menu": {
"title": "Annotations",
"items": [
"hide",
"show"
"show",
"-",
"create"
]
}
}
30 changes: 30 additions & 0 deletions src/modules/createAnnotations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const sketch = require("sketch/dom");
const ui = require("sketch/ui");

// Create a group named 'Annotations' from the selected layers
export default function() {
const document = sketch.getSelectedDocument();
const layers = document.selectedLayers.layers;

// Display message when no layer is selected
if (layers.length === 0) {
ui.message(`No layers selected.`);
return;
}

// Find to which parent the group should be attached
let parent = layers[0].parent;
if (!parent) {
parent = sketch.Page.fromNative(layers[0].sketchObject.parentPage());
}

// Create the group
const group = new sketch.Group({
parent: parent,
name: "Annotations",
layers: layers
});
group.adjustToFit();

ui.message(`New 'Annotations' group created from ${layers.length} layers.`);
}

0 comments on commit 8eeb58c

Please sign in to comment.