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

Create Layer Set if it doesn't already exist

Community Beginner ,
Apr 08, 2016 Apr 08, 2016

Happy Friday everyone.

I've been trying to figure out this JS where the script will create a layer set if there already isn't one of that name.

I've founds lots on how to create a layer set, but not how to do a conditional around it.

Any help would be appreciated.

Thank you.

TOPICS
Actions and scripting
699
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

Community Expert , Apr 08, 2016 Apr 08, 2016

This will work for a top level layer set:

#target photoshop

var doc=activeDocument;

var setName = 'My Set';

try{doc.activeDocument = doc.layerSets.getByName (setName)}

catch(e){

        doc.layerSets.add();

        doc.activeLayer.name = setName

    }

Translate
Adobe
Community Expert ,
Apr 08, 2016 Apr 08, 2016

My question is where would you want the layerset created if it doesn't exist? Does your file have nested layersets? Would you need to check the nested layersets if it does have them?

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
Community Beginner ,
Apr 08, 2016 Apr 08, 2016

It would be a top level layer set if it exists. Will be created there as well. The file may have nested layer sets but what I want to test for would not be nested.

-Tim

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
Community Expert ,
Apr 08, 2016 Apr 08, 2016

This will work for a top level layer set:

#target photoshop

var doc=activeDocument;

var setName = 'My Set';

try{doc.activeDocument = doc.layerSets.getByName (setName)}

catch(e){

        doc.layerSets.add();

        doc.activeLayer.name = setName

    }

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
Community Beginner ,
Apr 11, 2016 Apr 11, 2016

Thank you, Chuck Uebele‌.

As always, a huge help.

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
Community Expert ,
Apr 11, 2016 Apr 11, 2016

Glad I could help.

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
Community Beginner ,
Apr 11, 2016 Apr 11, 2016

I'd buy you a beer if you were local.

Or three...

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
Community Expert ,
Apr 11, 2016 Apr 11, 2016
LATEST

Well, if you're in the Los Angeles area...

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