over @ ps-scripts site, we’ve had kind of interesting discussion trying set scale on pattern fill layer styles 100% http://www.ps-scripts.com/bb/viewtopic.php?f=9&t=4875
mike hale’s proposed solution content out of pattern fill style (in hierarchy of layer’s descriptor), make new temporary layer, apply pattern fill – scale changed – temp layer, ask photoshop copy style temp layer original layer, , delete temp layer.
as far know, worked okay, wondered if possible without workaround, wrote script pull descriptor layer styles out, change scale on pattern fill styles, , save new layer styles layer.
this script worked sometimes, cause error when run more once in row (on cs4 , cs5, apparently not on cs6), set out investigate. turns out when fetching descriptor, several of properties specifying presets returned "de-localized" zstrings, instance '$$$/contours/defaults/linear=linear'. when setting descriptor, these must localized again, or else photoshop cs4/cs5 raise error (cs6 apparently able deal zstrings; haven’t tested versions <= cs3).
[one odd note script listener output produced in cs5 when creating drop shadow style contour other "linear" (for instance, using contour "cone") make photoshop throw error when run directly. necessary call localize on zstrings in script listener javascript before work (for instance, converting "$$$/contours/defaults/cone=cone" "cone").]
it seems work okay, however, raw byte stream fetched descriptor, search zstrings, call localize on them, , put localized strings in zstrings came from, before trying use descriptor change layer styles.
my last version of "set selected layer’s pattern fill style’s scale 100%" script that, , far can tell works across versions of photoshop, across platforms, , across other-language installs.
some of might find localizedescriptor function helpful, or general code getting/setting layer styles, should applicable variety of use cases.
var bytestostring, int16atoffset, int32atoffset, int32tobytes,
localizedescriptor, stringtobytes; int16atoffset = function(bytes, offset) { return ((bytes.charcodeat(offset)) << 8) +
bytes.charcodeat(offset + 1); }; int32atoffset = function(bytes, offset) { return ((int16atoffset(bytes, offset)) << 16) +
int16atoffset(bytes, offset + 2); }; int32tobytes = function(num) { var bytes; bytes = [num >>> 24, num << 8 >>> 24,
num << 16 >>> 24, num << 24 >>> 24]; return string.fromcharcode.apply(string, bytes); }; bytestostring = function(bytes) { var characters, i, n; characters = []
(i = 0, n = bytes.length; < n; += 2) { characters.push(int16atoffset(bytes, i)); } return string.fromcharcode.apply(string, characters); }; stringtobytes = function(string) { var bytes, char_code, i, n; bytes = []; (i = 0, n = string.length; < n; i++) { char_code = string.charcodeat(i); bytes.push(char_code >> 8, char_code & 0xff); } return string.fromcharcode.apply(string, bytes); }; localizedescriptor = function(desc) { var after_bytes, before_bytes, bytes, len, localized_string,
new_desc, new_len, offset, zstring; bytes = desc.tostream(); while (true) { offset = bytes.search(/text....\x00\$\x00\$\x00\$/); if (offset === -1) { break; } len = int32atoffset(bytes, offset + 4); zstring = bytestostring(bytes.substr(offset + 8, (len - 1) * 2)); localized_string = (localize(zstring)) + '\u0000'; new_len = localized_string.length; before_bytes = bytes.slice(0, offset); after_bytes = bytes.slice(offset + 8 + len * 2); bytes = before_bytes.concat(
'text', int32tobytes(new_len),
stringtobytes(localized_string), after_bytes); } new_desc = new actiondescriptor; new_desc.fromstream(bytes); return new_desc; }; var $s, duplicatedescriptor, executeset, gettargetlayereffects,
setpatternfillscale; $s = function(string) { return app.stringidtotypeid(string); }; duplicatedescriptor = function(descriptor) { var descriptorstream, newdescriptor; descriptorstream = descriptor.tostream(); newdescriptor = new actiondescriptor; newdescriptor.fromstream(descriptorstream); return newdescriptor; }; gettargetlayereffects = function() { var containerdesc, targetlayerref; targetlayerref = new actionreference; targetlayerref.putproperty($s('property'), $s('layereffects')); targetlayerref.putenumerated(
$s('layer'), $s('ordinal'), $s('targetenum')); containerdesc = app.executeactionget(targetlayerref); return containerdesc.getobjectvalue($s('layereffects')); }; executeset = function(target, to, type) { var action; action = new actiondescriptor; action.putobject($s('to'), type, to); action.putreference($s('target'), target); app.executeaction($s('set'), action, dialogmodes.no); }; setpatternfillscale = function(scale) { var currentpatternfill, layer, layereffects, newlayereffects,
newpatternfill, target; layereffects = gettargetlayereffects(); newlayereffects = duplicatedescriptor(layereffects); currentpatternfill = layereffects.getobjectvalue($s('patternfill')); newpatternfill = duplicatedescriptor(currentpatternfill); newpatternfill.putunitdouble($s('scale'), $s('percentunit'), 100); newlayereffects.putobject(
$s('patternfill'), $s('patternfill'), newpatternfill); newlayereffects = localizedescriptor(newlayereffects); layer = new actiondescriptor; layer.putobject(
$s('layereffects'), $s('layerfxvisible'), newlayereffects); target = new actionreference; target.putenumerated($s('layer'), $s('ordinal'), $s('targetenum')); executeset(target, layer, $s('layer')); }; setpatternfillscale(100); /* copyright (c) 2012 jacob rus permission hereby granted, free of charge, person obtaining copy of software , associated documentation files (the "software"), deal in software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of software, , permit persons whom software furnished so, subject following conditions: above copyright notice , permission notice shall included in copies or substantial portions of software. software provided "as is", without warranty of kind, express or implied, including not limited warranties of merchantability, fitness particular purpose , noninfringement. in no event shall authors or copyright holders liable claim, damages or other liability, whether in action of contract, tort or otherwise, arising from, out of or in connection software or use or other dealings in software. */
cheers.
[on separate subject, there way forum put code in monospaced font? wysiwyg editor isn’t wysiwyg (frankly, it’s rather terrible), , neither putting things in "pre"/"code" blocks, nor explicity setting font andale mono or courier new trick.]
just clear, recommended get/create new/copy approach because have tried years edit styles in place , ran undiscovered bug. agree better way change effect bug has been found. nice confirm works non-english version of photoshop.
to me easiest way insert code post here click on 'use advanced editor' link above top right edge of default editor. adds several new icons tool bar, 1 of >>( helptip = insert ) menu dropdown contains 'syntax highlighting'. has several choices. use 'plain'.
More discussions in Photoshop Scripting
adobe
Comments
Post a Comment