Created
September 20, 2017 08:14
-
-
Save noudadrichem/5c381e6a67cd152b57802bf39a597143 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
function cleanLayerStyless(array) { | |
var layers = [] | |
array.forEach(function(layer) { | |
if (layer.class() == 'MSShapeGroup') layers.push(layer) | |
}) | |
for (var i = 0; i < layers.length; i++) { | |
layers.forEach(function(layer, index) { | |
var fills = layer.style().fills() | |
fills.forEach(function(fill, fillIndex) { | |
log(layer.name()) | |
if (fill.isEnabled() == 0) { | |
log(fillIndex) | |
log(fill) | |
layer.style().removeStyleFillAtIndex(fillIndex) | |
} | |
}) | |
}) | |
} | |
} | |
function deleteUnusedStyles(context, dialog) { | |
if (dialog == undefined) dialog = false | |
var doc = context.document | |
var selection = context.selection | |
var layers = doc.currentPage().children() | |
var layerGroups = [] | |
layers.forEach(function(layer) { | |
if (layer.className() == 'MSShapeGroup') { | |
layerGroups.push(layer) | |
} | |
}) | |
if (!dialog) { | |
cleanLayerStyless(selection) | |
doc.showMessage("All selected layers have been cleaned") | |
} else { | |
cleanLayerStyless(layers) | |
doc.showMessage("All the layers have been cleaned") | |
} | |
} | |
deleteUnusedStyles(context, true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment