Skip to content

Instantly share code, notes, and snippets.

@nuzelac
Created August 31, 2012 22:39
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 nuzelac/3560268 to your computer and use it in GitHub Desktop.
Save nuzelac/3560268 to your computer and use it in GitHub Desktop.
setStrokeColor = function(strokeColor) {
var currentLayerEffects, currentStroke, key, layer, newLayerEffects, newStroke, target, _i, _j, _len, _len1, _ref, _ref1, effectColor;
currentLayerEffects = getTargetLayerEffects();
currentStroke = currentLayerEffects.getObjectValue($t('frameFX'));
newLayerEffects = new ActionDescriptor();
newStroke = new ActionDescriptor();
effectColor = new ActionDescriptor();
effectColor.putDouble(charIDToTypeID("Rd "), strokeColor.rgb.red);
effectColor.putDouble(charIDToTypeID("Grn "), strokeColor.rgb.green);
effectColor.putDouble(charIDToTypeID("Bl "), strokeColor.rgb.blue);
// loop through the keys of currentStroke, copying them over,
// unless the key is 'color', in which case set it to strokeColor argument
_ref = getKeys(currentStroke);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
key = _ref[_i];
if (key === ($t('color'))) {
newStroke.putObject(charIDToTypeID("Clr "), charIDToTypeID("RGBC"), effectColor);
} else {
copyDescriptorValue(currentStroke, newStroke, key);
}
}
// loop through the keys of currentLayerEffects, copying them over,
// unless the key is 'frameFX' (stroke ID), in which case set it to newStroke
_ref1 = getKeys(currentLayerEffects);
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
key = _ref1[_j];
if (key === ($t('frameFX'))) {
newLayerEffects.putObject($t('frameFX'), $t('frameFX'), newStroke);
} else {
copyDescriptorValue(currentLayerEffects, newLayerEffects, key);
}
}
layer = new ActionDescriptor();
layer.putObject($t('layerEffects'), $t('layerFXVisible'), newLayerEffects);
target = new ActionReference();
target.putEnumerated($t('layer'), $t('ordinal'), $t('targetEnum'));
executeSet(target, layer, $t('layer'));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment