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

Add new layer just above the active layer

Explorer ,
Oct 29, 2017 Oct 29, 2017

Hello,

I want to write a script which creates a new layer.

I'm using app.aciveDocument.artLayers.add() method, however it creates the new layer at the top of the layer list.

Is there any way to create the layer just above the active layer?

Thanks

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

People's Champ , Oct 29, 2017 Oct 29, 2017

You can use this method

var layer0 = app.activeDocument.activeLayer;

app.activeDocument.artLayers.add();

app.activeDocument.activeLayer.move(layer0, ElementPlacement.PLACEBEFORE);

Translate
Adobe
People's Champ ,
Oct 29, 2017 Oct 29, 2017

// mode_str = "Nrml"; "Lghn", "Drkn", "Nrml", "Clr ", "Lmns", etc...

////////////////////////////////////////////////////////////////////////////////////////////

function add_layer(name, op, mode_str, grp)

    {

    try {

        var desc3 = new ActionDescriptor();

        var ref1 = new ActionReference();

        ref1.putClass( charIDToTypeID( "Lyr " ) );

        desc3.putReference( charIDToTypeID( "null" ), ref1 );

        var desc4 = new ActionDescriptor();

        if (name != undefined) desc4.putString( charIDToTypeID( "Nm  " ), name);

        if (op   != undefined) desc4.putUnitDouble( charIDToTypeID( "Opct" ), charIDToTypeID( "#Prc" ), op );

        if (grp  != undefined) desc4.putBoolean( charIDToTypeID( "Grup" ), grp );

        if (mode_str != undefined)             

            {

            var mode = (mode_str.length==4) ? charIDToTypeID(mode_str) : stringIDToTypeID(mode_str);

            desc4.putEnumerated( charIDToTypeID( "Md  " ), charIDToTypeID( "BlnM" ), mode );

            }

        desc3.putObject( charIDToTypeID( "Usng" ), charIDToTypeID( "Lyr " ), desc4 );

        executeAction( charIDToTypeID( "Mk  " ), desc3, DialogModes.NO );

        ref1  = null;

        desc3 = null;

        desc4 = null;

        }

    catch(e) { alert(e); throw(e); }

    }

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
Engaged ,
Oct 29, 2017 Oct 29, 2017

If I understood correctly, this should work.

make();

function make() {

var descriptor = new ActionDescriptor();

var descriptor2 = new ActionDescriptor();

var reference = new ActionReference();

reference.putClass( stringIDToTypeID( "layer" ));

descriptor.putReference( charIDToTypeID( "null" ), reference );

descriptor.putObject( stringIDToTypeID( "using" ), stringIDToTypeID( "layer" ), descriptor2 );

executeAction( stringIDToTypeID( "make" ), descriptor, DialogModes.NO );

}

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 ,
Oct 29, 2017 Oct 29, 2017

Thank you guys for your replies.

I was hoping to be able achieve this using methods as per Adobe's JavaScript Scripting Reference.

Nevertheless thank you very much, really appreciated.

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
People's Champ ,
Oct 29, 2017 Oct 29, 2017

You can use this method

var layer0 = app.activeDocument.activeLayer;

app.activeDocument.artLayers.add();

app.activeDocument.activeLayer.move(layer0, ElementPlacement.PLACEBEFORE);

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 ,
Oct 29, 2017 Oct 29, 2017
LATEST

r-bin​ Thank you!

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