Skip to main content
chrisa90912733
Inspiring
August 23, 2018
Answered

Export combination of layers

  • August 23, 2018
  • 1 reply
  • 1713 views

Hi all,

At the moment I have a psd setup with two groups and a background layer as so:

ooXqi7C.png

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

This topic has been closed for replies.
Correct answer Kukurykus

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)

1 reply

Kukurykus
KukurykusCorrect answer
Legend
August 24, 2018

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)

chrisa90912733
Inspiring
August 26, 2018

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.

Kukurykus
Legend
August 27, 2018

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?