Last active
August 26, 2016 00:48
-
-
Save marianomike/67396a33a7450c9137b99a283ec43f0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import 'common.js' | |
var onRun = function(context) { | |
//reference the sketch document | |
var doc = context.document; | |
//reference what is selected | |
var selection = context.selection; | |
//make sure something is selected | |
if(selection.count() == 0){ | |
doc.showMessage("Please select something."); | |
}else{ | |
//loop through the selected layers | |
for(var i = 0; i < selection.count(); i++){ | |
//checks to see if the layer is a Symbol | |
if(selection[i].class() == "MSSymbolInstance"){ | |
//reference the selection | |
var layer = selection[i]; | |
//get the original layer name | |
var layerName = layer.name(); | |
//get the name of the symbol on the layer | |
var symbolName = layer.symbolMaster().name(); | |
//check if layer name is not already symbol name | |
if(layerName != symbolName){ | |
//set the layer name to the symbol name | |
layer.setName(symbolName); | |
var alertMessage = "Layer Name Changed from: "+layerName+ " to: "+symbolName; | |
alert("Layer Name Changed!", alertMessage); | |
}else{ | |
doc.showMessage("Layer name is already Symbol Name."); | |
} | |
}else{ | |
doc.showMessage("Please select a Symbol Layer."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment