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

create group from existing layers

Participant ,
Jun 16, 2020 Jun 16, 2020

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']);
TOPICS
Actions and scripting
1.6K
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 2 Correct answers

LEGEND , Jun 16, 2020 Jun 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)

 

Translate
LEGEND , Jun 16, 2020 Jun 16, 2020
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)
Translate
Adobe
Community Expert ,
Jun 16, 2020 Jun 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. 

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
Participant ,
Jun 16, 2020 Jun 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']);

 



 

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 ,
Jun 16, 2020 Jun 16, 2020
lrs = (aD = activeDocument).layers
inf = lrs['INFO'], icns = lrs['ICONS']

//	use here code to move layers to layerSet

inf.link(icns)
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
Participant ,
Jun 16, 2020 Jun 16, 2020

That linked the layers fine.

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 ,
Jun 16, 2020 Jun 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)

 

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
Participant ,
Jun 16, 2020 Jun 16, 2020

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

Mike

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 ,
Jun 16, 2020 Jun 16, 2020

Did you select both layers like I said?

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
Participant ,
Jun 16, 2020 Jun 16, 2020

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

Mike

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 ,
Jun 16, 2020 Jun 16, 2020
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)
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
Participant ,
Jun 16, 2020 Jun 16, 2020
LATEST

I think I will be owing you a few beers at this rate, runs very nicely

Many

 

thanks

Mike

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