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

Add new layer just above the active layer

Explorer ,
Oct 29, 2017 Oct 29, 2017

Copy link to clipboard

Copied

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

Views

830

Translate

Translate

Report

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);

Votes

Translate

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

Copy link to clipboard

Copied

// 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); }

    }

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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 );

}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

You can use this method

var layer0 = app.activeDocument.activeLayer;

app.activeDocument.artLayers.add();

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

r-bin​ Thank you!

Votes

Translate

Translate

Report

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