Copy link to clipboard
Copied
Hi all,
At the moment I have a psd setup with two groups and a background layer as so:
What I'm trying to do is run an export that saves a combination of these layers in sequence. e.g. 1st "Icon" + 1st "Colour" + Background then 2nd "Icon" + 1st "Colour" + Background until I have a copy of each icon with each of the available colours. Ideally I would also like the exported file to use the icon and colour names e.g. Hospital-Red.png, etc. The amount of icons and colours will increase over time so I'd need to take this into account also.
Is this something that's possible ?
Many thanks,
Chris
displayDialogs = DialogModes.NO
function sTT(v) {return stringIDToTypeID(v)}
runMenuItem(sTT('selectAllLayers'));
(ref = new ActionReference()).putEnumerated
(sTT('layer'), sTT('ordinal'), sTT('targetEnum'));
(lst = new ActionList()).putReference(ref);
(dsc = new ActionDescriptor()).putList(sTT('null'), lst)
executeAction(sTT('hide'), dsc)
runMenuItem(sTT('selectNoLayers')), aD = activeDocument
iL = (icn = aD.layers[0]).layers.length, icn.visible = true
cL = ( clr = aD.layers[1]).layers.leng
...Copy link to clipboard
Copied
displayDialogs = DialogModes.NO
function sTT(v) {return stringIDToTypeID(v)}
runMenuItem(sTT('selectAllLayers'));
(ref = new ActionReference()).putEnumerated
(sTT('layer'), sTT('ordinal'), sTT('targetEnum'));
(lst = new ActionList()).putReference(ref);
(dsc = new ActionDescriptor()).putList(sTT('null'), lst)
executeAction(sTT('hide'), dsc)
runMenuItem(sTT('selectNoLayers')), aD = activeDocument
iL = (icn = aD.layers[0]).layers.length, icn.visible = true
cL = ( clr = aD.layers[1]).layers.length, clr.visible = true
for(aHS = aD.activeHistoryState, i = 0; i < iL;) {
aD.activeHistoryState = aHS, aD.suspendHistory('', '');
(n1 = (lyr = aD.layers)[0].layers[i++]).visible = true
for(j = 0; j < cL;) {
(n2 = (c = lyr[1].layers[j++])).visible = true;
(sfw = new ExportOptionsSaveForWeb()).PNG8 = false
sfw.transparency = true, sfw.format = SaveDocumentType.PNG
fle = File(aD.path + '/' + n1.name + '-' + n2.name + '.png')
aD.exportDocument(fle, ExportType.SAVEFORWEB, sfw)
c.visible = false
}
}
aD.close(SaveOptions.DONOTSAVECHANGES)
Copy link to clipboard
Copied
Thanks, that's great. Would it be possible to add a progress bar as it's hard to tell how far along the process is with a large number of layers.
Copy link to clipboard
Copied
In CC 2018 change:
for(aHS = aD.activeHistoryState, i = 0; i < iL; i++) {
to:
pb = (win = new Window('palette'))
.add('progressbar'), win.show()
aHS = aD.activeHistoryState
for(i = 0; i < iL; i++) {
pb.value = (i + 1) / iL * 100; win.update()
As previous answer seems to satisfy you, why don't you mark my solution as correct answer?
Copy link to clipboard
Copied
I made the changes but now it misses half of the layers. At the moment I have 296 items in the icons folder and it only exports 592 combinations. It looks like it only processes 1st then 3rd and so on.
displayDialogs = DialogModes.NO
function sTT(v) {return stringIDToTypeID(v)}
runMenuItem(sTT('selectAllLayers'));
(ref = new ActionReference()).putEnumerated
(sTT('layer'), sTT('ordinal'), sTT('targetEnum'));
(lst = new ActionList()).putReference(ref);
(dsc = new ActionDescriptor()).putList(sTT('null'), lst)
executeAction(sTT('hide'), dsc)
runMenuItem(sTT('selectNoLayers')), aD = activeDocument
iL = (icn = aD.layers[0]).layers.length, icn.visible = true
cL = ( clr = aD.layers[1]).layers.length, clr.visible = true
pb = (win = new Window('palette'))
.add('progressbar'), win.show()
aHS = aD.activeHistoryState
for(i = 0; i < iL; i++) {
pb.value = (i + 1) / iL * 100; win.update()
aD.activeHistoryState = aHS, aD.suspendHistory('', '');
(n1 = (lyr = aD.layers)[0].layers[i++]).visible = true
for(j = 0; j < cL;) {
(n2 = (c = lyr[1].layers[j++])).visible = true;
(sfw = new ExportOptionsSaveForWeb()).PNG8 = false
sfw.transparency = true, sfw.format = SaveDocumentType.PNG
fle = File(aD.path + '/TEST/' + n1.name + '-' + n2.name + '.png')
aD.exportDocument(fle, ExportType.SAVEFORWEB, sfw)
c.visible = false
}
}
aD.close(SaveOptions.DONOTSAVECHANGES)
Copy link to clipboard
Copied
Change this line:
(n1 = (lyr = aD.layers)[0].layers[i++]).visible = true
to this one:
(n1 = (lyr = aD.layers)[0].layers[i]).visible = true