Skip to content

Instantly share code, notes, and snippets.

@designforhuman
Last active August 30, 2017 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save designforhuman/77c908b7075402fe20ab215928f83981 to your computer and use it in GitHub Desktop.
Save designforhuman/77c908b7075402fe20ab215928f83981 to your computer and use it in GitHub Desktop.
NameTag Generator
// NameTag Generator (alpha version)
// Designed and Coded by David Lee @DesignSpectrum, @Daylight
// 23 July, 2017
// array of participants' names
var participants = ["James", "Peter", "David"];
// get sketch document and layers(incl. artboard)
var sketch = context.api();
var document = sketch.selectedDocument;
var page = document.selectedPage;
var selectedLayers = document.selectedLayers;
var DISTANCE = 50;
// Give warning when artboard is not selected
if(selectedLayers.length == 0) {
log('Please select an artboard first.');
}
// duplicate the selected artboard
for(i = 0; i < participants.length; i++) {
selectedLayers.iterate(function(artboard) {
if(artboard.isArtboard) {
var newArtboard = artboard.duplicate();
var rect = newArtboard.frame;
rect.x += (i + 1) * (rect.width + DISTANCE);
newArtboard.frame = rect;
newArtboard.iterate(function(group) {
if(group.name == 'name') {
group.iterate(function(layer) {
if(layer.name == 'name') {
layer.text = participants[i];
}
});
}
});
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment