Copy link to clipboard
Copied
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']);
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)
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)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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']);
Copy link to clipboard
Copied
lrs = (aD = activeDocument).layers
inf = lrs['INFO'], icns = lrs['ICONS']
// use here code to move layers to layerSet
inf.link(icns)
Copy link to clipboard
Copied
That linked the layers fine.
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
This created the new group above existing layers but only put the top layer in the group.
Mike
Copy link to clipboard
Copied
Did you select both layers like I said?
Copy link to clipboard
Copied
No, my bad, something else I need to learn how to do
Mike
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
I think I will be owing you a few beers at this rate, runs very nicely
Many
thanks
Mike