jazz-y
Guide
jazz-y
Guide
Activity
‎Apr 03, 2020
12:03 AM
I am not saying that this is impossible 🙂 but I am saying that I do not know (and have not met) a working solution to such a situation. In my understanding, the general principle of working with layers is this: to work with attributes you do not need to make it active, to work with content, you need to make it active. Since the time required to select a layer is quite small, JJMack gave an excellent solution - remember which layer is selected, make the desired layer active, perform all necessary actions, restore the selection of the active layer.
... View more
‎Apr 02, 2020
11:49 PM
1 Upvote
This is strange. I tried several versions of Photoshop on the virtual machine (starting with cs6) and they all returned an error in the situation I described. Perhaps the result is affected by the fact that I'm testing only this one function without taking into account the preliminary processing of the document that your code can do. To a lesser extent, the result depends on the contents of the document.
... View more
‎Apr 02, 2020
07:30 AM
1 Upvote
Unfortunately, Action Manager in most cases does not allow working with the contents of a layer without activating it. For example, I can easily remove the layer mask without making it active (in example layerID = 2), but I can’t create a new mask in the same way - it will be created only for the active layer s2t = stringIDToTypeID;
(ref = new ActionReference()).putEnumerated( s2t( "channel" ), s2t( "channel" ), s2t( "mask" ));
(desc = new ActionDescriptor()).putReference( s2t( "null" ), ref );
(ref2 = new ActionReference()).putEnumerated( s2t('channel'), s2t('channel'), s2t('mask') );
ref2.putIdentifier(s2t( 'layer' ), 2)
desc.putReference( s2t('null'), ref2 )
executeAction( s2t( "delete" ), desc, DialogModes.NO ) It would be very nice if someone found a way to work with the contents of a layer without activating it.
... View more
‎Apr 02, 2020
06:36 AM
It’s strange. Your new example on my Photoshop 21.1.1 works just like the first one - the selection is created only if the layer is pre-activated on the palette. If no layer is selected, or a background layer is selected, then I get an error. What is your version of Photoshop? In the example above, I activated the layer only in one case - if there were no selected layers on the palette. In other cases, the state of the active layer did not change. I changed my code a bit - now it works in almost all cases: getSelectionFromLayerMask(2)
function getSelectionFromLayerMask(idx) {
s2t = stringIDToTypeID;
(docRef = new ActionReference()).putProperty(s2t("property"), s2t("targetLayers"))
docRef.putEnumerated(s2t("document"), s2t("ordinal"), s2t("targetEnum"))
var targetLayers = executeActionGet(docRef).hasKey(s2t("targetLayers"));
(docRef = new ActionReference()).putProperty(s2t("property"), s2t("numberOfLayers"))
docRef.putEnumerated(s2t("document"), s2t("ordinal"), s2t("targetEnum"))
var numberOfLayers = executeActionGet(docRef).getInteger(s2t("numberOfLayers"));
(lrRef = new ActionReference()).putProperty(s2t("property"), s2t("background"))
lrRef.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"))
var background = executeActionGet(lrRef).getBoolean(s2t("background"));
if (numberOfLayers == 1 && background) return;
(lrRef = new ActionReference()).putProperty(s2t("property"), s2t("hasUserMask"))
lrRef.putIndex(s2t("layer"), idx)
if (!executeActionGet(lrRef).getBoolean(s2t("hasUserMask"))) return;
if (!targetLayers || background) {
(ref = new ActionReference()).putIndex(s2t("layer"), 1);
(desc = new ActionDescriptor()).putReference(s2t("null"), ref);
executeAction(s2t("select"), desc, DialogModes.NO)
}
makeSelectionFromLayerMask(idx)
if (!targetLayers) {
(ref = new ActionReference()).putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
(desc = new ActionDescriptor()).putReference(s2t("null"), ref);
executeAction(s2t("selectNoLayers"), desc, DialogModes.NO)
}
if (background) {
(ref = new ActionReference()).putIndex(s2t("layer"), 0);
(desc = new ActionDescriptor()).putReference(s2t("null"), ref);
executeAction(s2t("select"), desc, DialogModes.NO)
}
function makeSelectionFromLayerMask(idx) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty(charIDToTypeID("Chnl"), charIDToTypeID("fsel"));
desc.putReference(charIDToTypeID("null"), ref);
var ref1 = new ActionReference();
ref1.putEnumerated(charIDToTypeID("Chnl"), charIDToTypeID("Chnl"), charIDToTypeID("Msk "));
ref1.putIndex(charIDToTypeID("Lyr "), idx);
desc.putReference(charIDToTypeID("T "), ref1);
executeAction(charIDToTypeID("setd"), desc, DialogModes.NO)
}
} The most time-consuming operation is directly creating a selection. The time to get the layer attributes is practically zero and can be neglected (especially since if you do not take care of additional checks, this will lead to an error).
... View more
‎Apr 02, 2020
12:38 AM
СС (jun 2013) is newer than CS6 (may 2012)
... View more
‎Apr 02, 2020
12:08 AM
2 Upvotes
in cs6 replace var output = [],
from = AM.getDocProperty('hasBackgroundLayer') ? 0 : 1,
to = AM.getDocProperty('numberOfLayers') with var output = [],
to = AM.getDocProperty('numberOfLayers'),
from = 0
try {app.activeDocument.backgroundLayer} catch(e) {from ++} Adobe periodically updates Action Manager properties of objects. There is no property "hasBackgroundLayer" in versions early than CC 😞
... View more
‎Apr 01, 2020
10:45 PM
1 Upvote
Action Manager uses a more detailed description of layer types: const kAnySheet = 0;
const kPixelSheet = 1;
const kAdjustmentSheet = 2;
const kTextSheet = 3;
const kVectorSheet = 4;
const kSmartObjectSheet = 5;
const kVideoSheet = 6;
const kLayerGroupSheet = 7;
const k3DSheet = 8;
const kGradientSheet = 9;
const kPatternSheet = 10;
const kSolidColorSheet = 11;
const kBackgroundSheet = 12;
const kHiddenSectionBounder = 13; try to use: s2t = stringIDToTypeID;
(ref = new ActionReference()).putProperty(s2t("property"), s2t("layerKind"))
ref.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"))
var activeLayerType = executeActionGet(ref).getInteger (s2t("layerKind"))
alert (activeLayerType)
... View more
‎Apr 01, 2020
11:28 AM
Reliability of image processing by neural networks is acceptable for entertainment content, but not for professional use. Photoshop is primarily a tool that gives you full control over each pixel in the image, and with the right skills, you can get a result significantly superior to automatic coloring.
... View more
‎Apr 01, 2020
03:06 AM
3 Upvotes
// SheetKind definitions from USheet.h const kAnySheet = 0; const kPixelSheet = 1; const kAdjustmentSheet = 2; const kTextSheet = 3; const kVectorSheet = 4; const kSmartObjectSheet = 5; const kVideoSheet = 6; const kLayerGroupSheet = 7; const k3DSheet = 8; const kGradientSheet = 9; const kPatternSheet = 10; const kSolidColorSheet = 11; const kBackgroundSheet = 12; const kHiddenSectionBounder = 13; (found in Adobe Photoshop\Required\CopyCSSToClipboard.jsx, tnx to r-bin)
... View more
‎Apr 01, 2020
12:33 AM
Your code contains an error, line: desc.putReference( charIDToTypeID("T "), ref1); should look like this: desc.putReference( charIDToTypeID( "T "), ref1); (perhaps something happened while loading the message, and initially this line was correct) Selection cannot be created if the layer palette does not have active (any) layer. Solving the problem is quite simple - before creating a selection, you need to check whether at least one layer is selected on the palette. If not, select it with a script and continue (if necessary, after creating the selection, you can restore (that is, remove) the selection), for example: var ref = new ActionReference()
ref.putProperty(s2t("property"), s2t("targetLayers"))
ref.putEnumerated(s2t("document"), s2t("ordinal"), s2t("targetEnum"))
if (!executeActionGet(ref).hasKey(s2t("targetLayers"))) {
var ref = new ActionReference()
ref.putIndex(s2t("layer"), 1)
var desc = new ActionDescriptor()
desc.putReference(s2t("null"), ref)
executeAction(s2t("select"), desc, DialogModes.NO)
// your code here
var ref = new ActionReference()
ref.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"))
var desc = new ActionDescriptor()
desc.putReference(s2t("null"), ref)
executeAction(s2t("selectNoLayers"), desc, DialogModes.NO)
}
function s2t(s) { return app.stringIDToTypeID(s) } Also may be useful to pre-check if the desired layer has user mask: function hasLayerUserMask (idx) {
var ref = new ActionReference()
ref.putProperty(s2t("property"), s2t("hasUserMask"))
ref.putIndex(s2t("layer"), idx)
return (executeActionGet(ref).getBoolean(s2t("hasUserMask")))
}
function s2t(s) { return app.stringIDToTypeID(s) }
... View more
‎Mar 31, 2020
11:48 PM
5 Upvotes
select all text layers, include layers in layerSets: var AM = new ActionManager
if (app.documents.length) selectTextLrs ()
function selectTextLrs() {
var output = [],
from = AM.getDocProperty('hasBackgroundLayer') ? 0 : 1,
to = AM.getDocProperty('numberOfLayers')
if (to) AM.deselectLayers ()
for (var i = from; i <= to; i++) {
if (AM.getLayerProperty('layerKind', i) == 3) AM.selectLayerByIndex (i,true)
}
}
function ActionManager() {
this.getDocProperty = function (property) {
property = s2t(property)
var ref = new ActionReference()
ref.putProperty(s2t("property"), property)
ref.putEnumerated(s2t("document"), s2t("ordinal"), s2t("targetEnum"))
return getDescValue(executeActionGet(ref), property)
}
this.getLayerProperty = function (property, index) {
property = s2t(property)
var ref = new ActionReference()
ref.putProperty(s2t("property"), property)
ref.putIndex(s2t("layer"), index)
return getDescValue(executeActionGet(ref), property)
}
this.selectLayerByIndex = function (idx, addToSelection) {
var desc = new ActionDescriptor()
var ref = new ActionReference()
ref.putIndex(s2t("layer"), idx)
desc.putReference(s2t("null"), ref)
if (addToSelection) desc.putEnumerated(s2t("selectionModifier"), s2t("addToSelectionContinuous"), s2t("addToSelection"))
executeAction(s2t("select"), desc, DialogModes.NO);
}
this.deselectLayers = function () {
var desc = new ActionDescriptor()
var ref = new ActionReference()
ref.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"))
desc.putReference(s2t("null"), ref)
executeAction(s2t("selectNoLayers"), desc, DialogModes.NO)
}
function getDescValue(desc, property) {
switch (desc.getType(property)) {
case DescValueType.OBJECTTYPE:
return (desc.getObjectValue(property));
break;
case DescValueType.LISTTYPE:
return desc.getList(property);
break;
case DescValueType.REFERENCETYPE:
return desc.getReference(property);
break;
case DescValueType.BOOLEANTYPE:
return desc.getBoolean(property);
break;
case DescValueType.STRINGTYPE:
return desc.getString(property);
break;
case DescValueType.INTEGERTYPE:
return desc.getInteger(property);
break;
case DescValueType.LARGEINTEGERTYPE:
return desc.getLargeInteger(property);
break;
case DescValueType.DOUBLETYPE:
return desc.getDouble(property);
break;
case DescValueType.ALIASTYPE:
return desc.getPath(property);
break;
case DescValueType.CLASSTYPE:
return desc.getClass(property);
break;
case DescValueType.UNITDOUBLE:
return (desc.getUnitDoubleValue(property));
break;
case DescValueType.ENUMERATEDTYPE:
return (t2s(desc.getEnumerationValue(property)));
break;
case DescValueType.RAWTYPE:
var tempStr = desc.getData(property);
var rawData = new Array();
for (var tempi = 0; tempi < tempStr.length; tempi++) {
rawData[tempi] = tempStr.charCodeAt(tempi);
}
return rawData;
break;
default:
break;
};
}
function s2t(s) { return stringIDToTypeID(s) }
function t2s(t) { return typeIDToStringID(t) }
}
... View more
‎Mar 30, 2020
03:00 AM
1 Upvote
I don’t know how to hack keyboard shortcuts in Photoshop. Therefore, for many years I have been using the X-keys XK-24 Programmable Keypad (24 keys, 2 layers) - once I set it up, printed out paper with icons and signatures and forgot about the problem of complex hot keys in several applications.
... View more
‎Mar 30, 2020
12:46 AM
3 Upvotes
Photoshop uses separate Foreground / Background Color for regular drawing and for working with masks. Set colors AFTER selecting a channel with a mask (if you need them to work with mask).
... View more
‎Mar 26, 2020
01:12 AM
3 Upvotes
As far as I know, the script cannot access the pixels of the image directly. If you stay within the scripting language of Photoshop, that is, a very long and inefficient way of working with pixels is to read each pixel through the colorSampler tool, process the resulting array, then assign a color to each pixel through make selection & fill. It is really very long and inefficient. A more effective option is to save the image to disk and transfer its processing to an external script / program, and then upload the result to Photoshop.
... View more
‎Mar 25, 2020
11:01 AM
I tried this code in several ways, but still did not understand how to check custom option exists in my scripts 😞 (dsc = new ActionDescriptor()).putString(stringIDToTypeID('javaScriptName'), 'someItem')
dsc.putString(stringIDToTypeID('javaScriptMessage'), '''undefined''')
executeAction(stringIDToTypeID('AdobeScriptAutomation Scripts'), dsc, DialogModes.NO) This code simply runs the script, regardless of whether the settings were saved or not (the main thing is that the script is installed)
... View more
‎Mar 25, 2020
04:54 AM
3 Upvotes
if (app.documents.length) {
try { var f = app.activeDocument.fullName } catch (e) {
var p = new Folder; f = p.selectDlg(); if (f) f = File(f + '/' + app.activeDocument.name)
}
if (f) {
(o = new JPEGSaveOptions ()).quality = 12
activeDocument.saveAs(createUniqueFileName(f), o)
activeDocument.close()
}
}
function createUniqueFileName(f) {
var inPath = decodeURI(f.parent),
inFile = decodeURI(f.name).replace(/\.[^\.]+$/, '').replace(/_\d+$/,''),
inExt = '.jpg',
uniqueFileName = File(inPath + '/' + inFile + inExt),
fileNumber = 1
while (uniqueFileName.exists) {
uniqueFileName = File(inPath + '/' + inFile + "_" + ('000' + fileNumber).slice(-3) + inExt)
fileNumber++;
}
return uniqueFileName
}
... View more
‎Mar 25, 2020
12:41 AM
1 Upvote
Perhaps this is not about a signature, but about metadata. In some cases, I had problems due to the large amount of metadata that Photoshop writes to a file. The easiest way to remove them is exiftool.
... View more
‎Mar 24, 2020
12:35 PM
3 Upvotes
I like getting the list of layers through AM - it's fast and it's one loop: var AM = new ActionManager,
layerSetArray = app.documents.length ? getAllLayers() : []
function getAllLayers() {
var output = [],
from = AM.getDocProperty('hasBackgroundLayer') ? 0 : 1,
len = AM.getDocProperty('numberOfLayers')
for (var i = from; i <= len; i++) {
if (AM.getLayerProperty('layerSection', i) == 'layerSectionEnd') continue;
var id = AM.getLayerProperty('layerID', i),
title = AM.getLayerProperty('name', i)
output.push({ id: id, name: title })
}
return output
}
function ActionManager() {
this.getDocProperty = function (property) {
property = s2t(property)
var ref = new ActionReference()
ref.putProperty(s2t("property"), property)
ref.putEnumerated(s2t("document"), s2t("ordinal"), s2t("targetEnum"))
return getDescValue(executeActionGet(ref), property)
}
this.getLayerProperty = function (property, index) {
property = s2t(property)
var ref = new ActionReference()
ref.putProperty(s2t("property"), property)
ref.putIndex(s2t("layer"), index)
return getDescValue(executeActionGet(ref), property)
}
this.selectLayerById = function (id, addToSelection) {
var desc = new ActionDescriptor()
var ref = new ActionReference()
ref.putIdentifier(s2t("layer"), id)
desc.putReference(s2t("null"), ref)
if (addToSelection) desc.putEnumerated(s2t("selectionModifier"), s2t("addToSelectionContinuous"), s2t("addToSelection"))
executeAction(s2t("select"), desc, DialogModes.NO);
}
function getDescValue(desc, property) {
switch (desc.getType(property)) {
case DescValueType.OBJECTTYPE:
return (desc.getObjectValue(property));
break;
case DescValueType.LISTTYPE:
return desc.getList(property);
break;
case DescValueType.REFERENCETYPE:
return desc.getReference(property);
break;
case DescValueType.BOOLEANTYPE:
return desc.getBoolean(property);
break;
case DescValueType.STRINGTYPE:
return desc.getString(property);
break;
case DescValueType.INTEGERTYPE:
return desc.getInteger(property);
break;
case DescValueType.LARGEINTEGERTYPE:
return desc.getLargeInteger(property);
break;
case DescValueType.DOUBLETYPE:
return desc.getDouble(property);
break;
case DescValueType.ALIASTYPE:
return desc.getPath(property);
break;
case DescValueType.CLASSTYPE:
return desc.getClass(property);
break;
case DescValueType.UNITDOUBLE:
return (desc.getUnitDoubleValue(property));
break;
case DescValueType.ENUMERATEDTYPE:
return (t2s(desc.getEnumerationValue(property)));
break;
case DescValueType.RAWTYPE:
var tempStr = desc.getData(property);
var rawData = new Array();
for (var tempi = 0; tempi < tempStr.length; tempi++) {
rawData[tempi] = tempStr.charCodeAt(tempi);
}
return rawData;
break;
default:
break;
};
}
function s2t(s) { return stringIDToTypeID(s) }
function t2s(t) { return typeIDToStringID(t) }
} As a rule, I get all the necessary attributes in this loop (getting the name and ID of the layer in the example below) and put them in an object, the array of which the function returns. For further processing, i can also use AM code and access to the layer via his ID, or use the DOM through AM.selectLayerById (), for example: for (var i=0; i<layerSetArray.length; i++){
AM.selectLayerById (layerSetArray[i].id)
alert (app.activeDocument.activeLayer.name)
} (I never use .getByName () since a document can contain several layers with the same name) Maybe it will help you.
... View more
‎Mar 24, 2020
05:28 AM
2 Upvotes
I don’t think that someone will be able to help without your action file or screenshot of the action panel with expanded commands
... View more
‎Mar 24, 2020
02:38 AM
3 Upvotes
if (app.documents.length) {
try { var f = app.activeDocument.fullName } catch (e) {
var p = new Folder; f = p.selectDlg(); if (f) f = File(f + '/' + app.activeDocument.name)
}
if (f) {
activeDocument.saveAs(createUniqueFileName(f))
activeDocument.close()
}
}
function createUniqueFileName(f) {
var inPath = decodeURI(f.parent),
inFile = decodeURI(f.name).replace(/\.[^\.]+$/, '').replace(/_\d+$/,''),
inExt = '.psd',
uniqueFileName = File(inPath + '/' + inFile + inExt),
fileNumber = 1
while (uniqueFileName.exists) {
uniqueFileName = File(inPath + '/' + inFile + "_" + ('000' + fileNumber).slice(-3) + inExt)
fileNumber++;
}
return uniqueFileName
} * saving only in psd (with default params) to the same folder from which the document was opened, or to the specified folder (if the document has not yet been saved)
... View more
‎Mar 22, 2020
04:25 AM
1 Upvote
try this: for (var i=0; i<app.documents.length; i++) {
var doc = app.activeDocument = app.documents[i],
f = doc.fullName
doc.saveAs (File(f.path + "/" + decodeURI(f.name).replace(/\.\S+$/, "") + ".psd"))
f.remove()
} * i think I understand what the geppettol66959005 needs
... View more
‎Mar 21, 2020
10:16 PM
1 Upvote
What is wrong with this code? for (var i=0; i<app.documents.length; i++) {
var f = app.documents[i].fullName,
p = f.path,
n = decodeURI(f.name).replace(/\.\S+$/, "")
app.documents[i].saveAs (File(p + "/" + n + ".psd"))
f.remove() // removes original file, delete this line if it is not necessary
}
... View more
‎Mar 21, 2020
11:19 AM
2 Upvotes
... in any case, it is better faster to get a separate property than the whole desc object ...
... View more
‎Mar 21, 2020
10:34 AM
2 Upvotes
Great short code! I was sure that if the necessary property not found, executeActionGet (ref) will cause an error...
... View more
‎Mar 21, 2020
09:58 AM
1 Upvote
... also document names may contain characters not supported by the current file system, there may be other errors while saving the file (read only or inaccessible folder), etc. - all this things needs to be processed... I think that geppettol66959005 just does not need it.
... View more
‎Mar 21, 2020
06:51 AM
2 Upvotes
save all open documents in psd in the same path as the original files and rename the source file from test.jpg to test.psd for (var i=0; i<app.documents.length; i++) {
var f = app.documents[i].fullName,
p = f.path,
n = decodeURI(f.name).replace(/\.\S+$/, "")
app.documents[i].saveAs (File(p + "/" + n + ".psd"))
f.remove() // removes original file, delete this line if it is not necessary
} * unsaved documents that do not have a disk path will cause an error. In this case, the c_pfaffenbichler code is more suitable
... View more
‎Mar 20, 2020
11:18 AM
1 Upvote
moveLayerSetWithMask(app.activeDocument.layerSets[0], 0, new UnitValue(20, 'px'))
function moveLayerSetWithMask(lrSet, dH, dV) {
var id = lrSet.id
if (hasLayerUserMask(id)) {
var linked = getUserMaskLinkedState(id)
setUserMaskLinkedState(id, true)
lrSet.translate(dH, dV)
setUserMaskLinkedState(id, linked)
} else {
lrSet.translate(dH, dV)
}
function setUserMaskLinkedState(id, linked) {
desc = new ActionDescriptor(),
desc2 = new ActionDescriptor(),
ref = new ActionReference()
ref.putIdentifier(s2t("layer"), id)
desc.putReference(s2t("null"), ref)
desc2.putBoolean(s2t("userMaskLinked"), linked)
desc.putObject(s2t("to"), s2t("layer"), desc2)
executeAction(s2t("set"), desc, DialogModes.NO)
}
function getUserMaskLinkedState(id) {
ref = new ActionReference()
ref.putProperty(s2t("property"), s2t("userMaskLinked"))
ref.putIdentifier(s2t("layer"), id)
return executeActionGet(ref).getBoolean(s2t("userMaskLinked"))
}
function hasLayerUserMask(id) {
ref = new ActionReference()
ref.putProperty(s2t("property"), s2t("hasUserMask"))
ref.putIdentifier(s2t("layer"), id)
return executeActionGet(ref).getBoolean(s2t("hasUserMask"))
}
function s2t (s) { return app.stringIDToTypeID(s) }
}
... View more
‎Mar 18, 2020
11:26 PM
1 Upvote
Menu selection commands return an empty descriptor. We do not know state of menu item before executeAction command and after. We can only switch it.
... View more
‎Mar 18, 2020
11:25 AM
1 Upvote
cb1.value = activeDocument.guides.length ?
... View more
‎Mar 16, 2020
07:56 AM
1 Upvote
1. Search all raw files from current folder and subfolders (use search panel of windows explorer or other file manager) 2. Drag all files to photoshop - it will be open in ACR plugin 3. Select all and save raw files in jpg with option "save in same directory" 4. After saving mark files to delete in ACR plugin, or delete it manually in file manager
... View more