Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Export combination of layers

Explorer ,
Aug 23, 2018 Aug 23, 2018

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

TOPICS
Actions and scripting
1.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 23, 2018 Aug 23, 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.leng

...
Translate
Adobe
LEGEND ,
Aug 23, 2018 Aug 23, 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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 26, 2018 Aug 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 26, 2018 Aug 26, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 27, 2018 Aug 27, 2018

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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 27, 2018 Aug 27, 2018
LATEST

Change this line:

(n1 = (lyr = aD.layers)[0].layers[i++]).visible = true

to this one:

(n1 = (lyr = aD.layers)[0].layers[i]).visible = true
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines