Copy link to clipboard
Copied
Seems really basic, but keep having problems moving a group inside another group (tested CC 2014 and 2015). So following code throws an illegal argument error at the .move-line (I've also tried other variants like .PLACEATBEGINNING and .INSIDE):
var doc = app.documents.add( 256, 256, 72, "foo")
var group1 = doc.layerSets.add()
var group2 = doc.layerSets.add()
group1.move(group2, ElementPlacement.PLACEATEND)
doc.close(SaveOptions.DONOTSAVECHANGES)
But this way works OK
var doc = app.documents.add( 256, 256, 72, "foo")
var group1 = doc.layerSets.add()
var group2 = doc.layerSets.add()
var layer1 = group1.artLayers.add()
var layer2 = group2.artLayers.add()
group1.move(layer2 , ElementPlacement.PLACEAFTER)
doc.close(SaveOptions.DONOTSAVECHANGES)
Any cracked what limitations are in play here? You can do latter, but then you might need to create & remove tmp layers to use as target.
Yes it has been a problem, but you can use AM.
...var doc = app.documents.add( 256, 256, 72, "foo");
doc.layerSets.add();
var group1 = getLayerID();
doc.layerSets.add();
var group2 = getLayerID();
moveLayerToLayerSet( group2, group1);
function moveLayerToLayerSet( fromID, toID ){
var desc5 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putIdentifier( charIDToTypeID('Lyr '), Number(fromID) );
desc5.putReference( charIDToTypeID('null'), ref4 );
var ref5 = new ActionReference();
r
Copy link to clipboard
Copied
Yes it has been a problem, but you can use AM.
var doc = app.documents.add( 256, 256, 72, "foo");
doc.layerSets.add();
var group1 = getLayerID();
doc.layerSets.add();
var group2 = getLayerID();
moveLayerToLayerSet( group2, group1);
function moveLayerToLayerSet( fromID, toID ){
var desc5 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putIdentifier( charIDToTypeID('Lyr '), Number(fromID) );
desc5.putReference( charIDToTypeID('null'), ref4 );
var ref5 = new ActionReference();
ref5.putIndex( charIDToTypeID('Lyr '), getLayerIndexByID(toID) );
desc5.putReference( charIDToTypeID('T '), ref5 );
desc5.putBoolean( charIDToTypeID('Adjs'), false );
desc5.putInteger( charIDToTypeID('Vrsn'), 5 );
try{
executeAction( charIDToTypeID('move'), desc5, DialogModes.NO );
}catch(e){alert(e);}
};
function getLayerID(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '),charIDToTypeID('Ordn'),charIDToTypeID('Trgt') );
var desc = executeActionGet(ref);
return desc.getInteger(stringIDToTypeID( 'layerID' ));
};
function getLayerIndexByID(ID){
var ref = new ActionReference();
ref.putIdentifier( charIDToTypeID('Lyr '), ID );
try{
activeDocument.backgroundLayer;
return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1;
}catch(e){
return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ));
}
};
Copy link to clipboard
Copied
Thanks. Amazingly I've managed to (unintentionally) avoid this issue so far by always moving layers to document root. But now with Artboards can't be avoided