Skip to main content
Inspiring
June 16, 2020
Answered

create group from existing layers

  • June 16, 2020
  • 2 replies
  • 1741 views

I have 2 layers that I wish to place in a new group called DATA, they have just been linked by the follwing code and so I can learn a bit more is it better to create the group first and add layers to it or does that not matter?

activeDocument.layers['INFO'].link(activeDocument.layers['ICONS']);
This topic has been closed for replies.
Correct answer Kukurykus

No, my bad, something else I need to learn how to do

Mike


sTT =stringIDToTypeID, dsc = new ActionDescriptor(), ref = new ActionReference()
for(i = 0; i < (a = ['INFO', 'ICONS']).length;) ref.putName(sTT('layer'), a[i++])
dsc.putReference(sTT('null'), ref), executeAction(sTT('select'), dsc)

2 replies

Kukurykus
Legend
June 16, 2020

Select both layers (to be grouped) and use this code:

 

 sTT = stringIDToTypeID;
 
(ref1 = new ActionReference()).putClass(sTT('layerSection'));
(dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1);
(ref2 = new ActionReference()).putEnumerated(sTT('layer'), sTT('ordinal'), sTT('targetEnum'))
dsc1.putReference(sTT('from'), ref2); (dsc2 = new ActionDescriptor()).putString(sTT('name'), 'DATA')
dsc1.putObject(sTT('using'), sTT('layerSection'), dsc2), executeAction(sTT('make'), dsc1)

 

Inspiring
June 16, 2020

This created the new group above existing layers but only put the top layer in the group.

Mike

Kukurykus
Legend
June 16, 2020

Did you select both layers like I said?

c.pfaffenbichler
Community Expert
Community Expert
June 16, 2020

Do you want to use DOM-code or AM-code? 

 

Referencing Layers by name seems a bit risky by the way. 

If you created the Layers withing the Script you may want to define them as a var right away. 

Inspiring
June 16, 2020

In all honesty I do not know the difference between the 2 types of code

The layer names will always be the same as they are created in the script

I have just found a way to create a Group (but this may not be the best method obviously)

 

 

	var docRef = app.activeDocument;
	var newGroup = docRef.layerSets.add();
	newGroup.name = "DATA";

 

so if I add that early enough I can use the following to add the layers to the group using after each new layer

 

activeDocument.activeLayer.move(docRef.layerSets["DATA"], ElementPlacement.INSIDE);

 


but when I try to run this I get an error

 

	activeDocument.layers['INFO'].link(activeDocument.layers['ICONS']);

 



 

Kukurykus
Legend
June 16, 2020
lrs = (aD = activeDocument).layers
inf = lrs['INFO'], icns = lrs['ICONS']

//	use here code to move layers to layerSet

inf.link(icns)