Skip to main content
Participating Frequently
November 15, 2011
Answered

Move LayerSet to another

  • November 15, 2011
  • 1 reply
  • 5856 views

Hi,

I have small problam with move one layerset to another.

var folder = app.activeDocument.layerSets.add();

app.activeDocument.activeLayer.name = app.activeDocument.name;

for(var j = layers.length-1; j >= 0; j--){

        var layer = layers;

        app.activeDocument.activeLayer = layer;

        if(layer != folder) {

            layer.move(folder, ElementPlacement.INSIDE); // <=========== HERE IS PROBLEM

        }

}

I want move layerset STAR to STAR.PSD with all content.

Can you tell me, where is problem??

Than you Domaneni

This topic has been closed for replies.
Correct answer Michael_L_Hale

Where you able to get the scriptlistener log to output using the layerSet name in the to reference or did you edit the log file? I have only been able get it to output index. And it doesn't seem to work by name. I would do something like this.

var sourceLayerSet = app.activeDocument.layers.getByName('Star');

var destinationLayerSet = app.activeDocument.layers.getByName('Star.psd');

moveLayerSet( sourceLayerSet, destinationLayerSet );

function moveLayerSet( fromLayer, toLayer ){// layerSet objects

    var desc = new ActionDescriptor();

        var sourceRef = new ActionReference();

        sourceRef.putName( charIDToTypeID( "Lyr " ), fromLayer.name );

    desc.putReference( charIDToTypeID( "null" ), sourceRef );

            var indexRef = new ActionReference();

            indexRef.putName( charIDToTypeID("Lyr "), toLayer.name );

            var layerIndex = executeActionGet(indexRef).getInteger(stringIDToTypeID('itemIndex'));

        var destinationRef = new ActionReference();

        destinationRef.putIndex( charIDToTypeID( "Lyr " ), layerIndex-1 );

    desc.putReference( charIDToTypeID( "T   " ), destinationRef );

    desc.putBoolean( charIDToTypeID( "Adjs" ), false );

    desc.putInteger( charIDToTypeID( "Vrsn" ), 5 );

    executeAction( charIDToTypeID( "move" ), desc, DialogModes.NO );

}

1 reply

Inspiring
November 15, 2011

For what it is worth, trying to move a layerset into another layerset has never worked for me either.

// throws Illegal Argument error

//app.activeDocument.layers.getByName('Star').move(app.activeDocument.layers.getByName('Star.psd'),ElementPlacement.INSIDE);

// throws error saying you can't dupe set into another set

// but you can in the GUI or by using scriptlistener

//app.activeDocument.layers.getByName('Star').duplicate(app.activeDocument.layers.getByName('Star.psd'),ElementPlacement.INSIDE);

// does move the artLayer

app.activeDocument.layers.getByName('Star').artLayers[0].move(app.activeDocument.layers.getByName('Star.psd'),ElementPlacement.INSIDE);

// does dupe the artLayer

app.activeDocument.layers.getByName('Star').artLayers[0].duplicate(app.activeDocument.layers.getByName('Star.psd'),ElementPlacement.INSIDE);

As noted you can move or dupe a layerset into another layerset using scriptlistener. But you have to work out the layerSets's Action Manager index.

DomaneniAuthor
Participating Frequently
November 15, 2011

I wrote this, but it isn't corect.

Can you help me with this??

function moveLayerToLayer(fromLayer, toLayer){

    var id766 = charIDToTypeID( "slct" );

    var desc45 = new ActionDescriptor();

    var id767 = charIDToTypeID( "null" );

    var ref9 = new ActionReference();

    var id768 = charIDToTypeID( "Lyr " );

    ref9.putName( id768, fromLayer);

    desc45.putReference( id767, ref9 );

    var id769 = charIDToTypeID( "MkVs" );

    desc45.putBoolean( id769, false );

    executeAction( id766, desc45, DialogModes.NO);

    //=====================================

    var id770 = charIDToTypeID( "move" );

   

   

    var desc46 = new ActionDescriptor();

    var id771 = charIDToTypeID( "null" );

    var ref10 = new ActionReference();

    var id772 = charIDToTypeID( "Lyr " );

    var id773 = charIDToTypeID( "Ordn" );

    var id774 = charIDToTypeID( "Trgt" );

    ref10.putEnumerated( id772, id773, id774 );

    desc46.putReference( id771, ref10 );

    var id775 = charIDToTypeID( "T   " );

    var ref11 = new ActionReference();

    var id776 = charIDToTypeID( "Lyr " );

    ref11.putName( id776, toLayer);

    desc46.putReference( id775, ref11 );

    var id777 = charIDToTypeID( "Vrsn" );

    desc46.putInteger( id777, 2 );

    executeAction( id770, desc46, DialogModes.NO );

   

}

Michael_L_HaleCorrect answer
Inspiring
November 15, 2011

Where you able to get the scriptlistener log to output using the layerSet name in the to reference or did you edit the log file? I have only been able get it to output index. And it doesn't seem to work by name. I would do something like this.

var sourceLayerSet = app.activeDocument.layers.getByName('Star');

var destinationLayerSet = app.activeDocument.layers.getByName('Star.psd');

moveLayerSet( sourceLayerSet, destinationLayerSet );

function moveLayerSet( fromLayer, toLayer ){// layerSet objects

    var desc = new ActionDescriptor();

        var sourceRef = new ActionReference();

        sourceRef.putName( charIDToTypeID( "Lyr " ), fromLayer.name );

    desc.putReference( charIDToTypeID( "null" ), sourceRef );

            var indexRef = new ActionReference();

            indexRef.putName( charIDToTypeID("Lyr "), toLayer.name );

            var layerIndex = executeActionGet(indexRef).getInteger(stringIDToTypeID('itemIndex'));

        var destinationRef = new ActionReference();

        destinationRef.putIndex( charIDToTypeID( "Lyr " ), layerIndex-1 );

    desc.putReference( charIDToTypeID( "T   " ), destinationRef );

    desc.putBoolean( charIDToTypeID( "Adjs" ), false );

    desc.putInteger( charIDToTypeID( "Vrsn" ), 5 );

    executeAction( charIDToTypeID( "move" ), desc, DialogModes.NO );

}