Copy link to clipboard
Copied
Hello Everyone
I have one script which move and place currently selected layer above the "LOGO" layer (LOGO is layer's name). Script is working perfectly when logo layer is not inside any group but if logo layer is inside any group this script doesn't work and give error
Error1302:NO such element
Line:6
-> var layerRef=app.activeDocument.layers.getByName('LOGO');
What changes are required in this script ? Kindly help. I am using photoshop cs3
Below is my current script
Try this. You need to start with the layer you want to move selected.
#target photoshop
var doc = activeDocument;
var moveLay = doc.activeLayer
var curLayer
var targetLay
goThroughLayers (doc);
doc.activeLayer = moveLay;
moveLay.move (targetLay, ElementPlacement.PLACEBEFORE)
function goThroughLayers(parentLayer){
for(var i=0;i<parentLayer.layers.length;i++){
curLayer = parentLayer.layers[i];
doc.activeLayer = curLayer;
if(curLayer.typename =='LayerSet'){goThroughLay
...
Copy link to clipboard
Copied
Update : Currently selected layer could be anything like text layer, smart object layer etc
Copy link to clipboard
Copied
You have to search within the group. Using AM code. To search the entire document, I generally us a recursive function that will go through all layers, and if it comes across a group, it will restart the search within that group. There are faster ways, by using AM code, but I would have to look that up, as I'm not that proficient with it.
Copy link to clipboard
Copied
Thank you @Chuck Uebele sir. Let me try few more time according to your suggestion.
Copy link to clipboard
Copied
Hello sir I found one script which select the LOGO layer no matter it is inside group or outside group but I don't know how to make it layer Reference
I mean this ///var layerRef = app.activeDocument.layers.getByName( 'LOGO' );)
here is that script
(Sorry if I am trying to solve the problem in a wrong way)
Copy link to clipboard
Copied
This link, might have a start on using AM code to search all layers.
Copy link to clipboard
Copied
Thank you sir..Let me check the link and try.
Copy link to clipboard
Copied
Here's a link with code that I posted for a recursive function.
Copy link to clipboard
Copied
Sir I checked the code which you mentioned. I am trying to learn. This is what I found
Copy link to clipboard
Copied
The script mentioned in your link is searching the LOGO layer perfectly but I am not able to place previously selected layer above logo layer. Please check the screenshot I uploaded with my main post.
Copy link to clipboard
Copied
I will have to check later, as I'maway from my computer.. There was an issue with one of the place locations that didn't work with a group.
Copy link to clipboard
Copied
This AM based function will select the first layer found by name, even if it is inside nested layer sets of the same name (it only selected layers, not groups/sets).
// Select layer by name, not set/group of same name
selectLayerName("LOGO");
function selectLayerName(lyrName) {
var idselect = stringIDToTypeID( "select" );
var desc266 = new ActionDescriptor();
var idnull = stringIDToTypeID( "null" );
var ref59 = new ActionReference();
var idlayer = stringIDToTypeID( "layer" );
ref59.putName( idlayer, lyrName );
desc266.putReference( idnull, ref59 );
var idmakeVisible = stringIDToTypeID( "makeVisible" );
desc266.putBoolean( idmakeVisible, false );
var idlayerID = stringIDToTypeID( "layerID" );
var list41 = new ActionList();
list41.putInteger( 3 );
desc266.putList( idlayerID, list41 );
executeAction( idselect, desc266, DialogModes.NO );
}
And here it is "beautified" through Clean SL:
// Select layer by name, not set/group of same name
selectLayerName("LOGO");
function selectLayerName(lyrName) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var list = new ActionList();
var reference = new ActionReference();
reference.putName( s2t( "layer" ), lyrName );
descriptor.putReference( s2t( "null" ), reference );
descriptor.putBoolean( s2t( "makeVisible" ), false );
list.putInteger( 3 );
descriptor.putList( s2t( "layerID" ), list );
executeAction( s2t( "select" ), descriptor, DialogModes.NO );
}
Copy link to clipboard
Copied
Hello sir, Thanks for the reply but your code is selecting first layer found by name, even if it is inside nested layer sets of the same name (it only selected layers, not groups/sets).
Selecting LOGO layer is not an issue. I think I am not able to convey my message properly. Please check my original post. I want to move active layer above LOGO layer. I dont want to select LOGO layer. Please check the screenshot attached. The script which is posted in main post move the activelayer above LOGO layer if LOGO layer is not inside any group. Script doesnt work if LOGO layer is inside any group. In my original LOGO layer is used as layer referenece in line 6
)
Thanks & Regards
Copy link to clipboard
Copied
@Amelia24456658fkpp wrote:Selecting LOGO layer is not an issue. I think I am not able to convey my message properly.
I thought it was as you originally wrote:
Script is working perfectly when logo layer is not inside any group but if logo layer is inside any group this script doesn't work and give error...
Apologies, there are probably better ways, however, by selecting the LOGO layer, you can get it's layer ID, then you can move your target layer to the layer ID position above the LOGO layer... Or so I was thinking, I haven't had time to test that though.
Looks like Chuck has come to the rescue again!
Copy link to clipboard
Copied
This is what I was referring to above. Have the layer active that you would like to move above the layer named LOGO:
#target photoshop
var targetLayer = activeDocument.activeLayer;
selectLayerName("LOGO");
var logoID = activeDocument.activeLayer.id;
activeDocument.activeLayer = targetLayer;
moveLayerInStack(logoID + 1);
function selectLayerName(lyrName) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var list = new ActionList();
var reference = new ActionReference();
reference.putName( s2t( "layer" ), lyrName );
descriptor.putReference( s2t( "null" ), reference );
descriptor.putBoolean( s2t( "makeVisible" ), false );
list.putInteger( 3 );
descriptor.putList( s2t( "layerID" ), list );
executeAction( s2t( "select" ), descriptor, DialogModes.NO );
}
function moveLayerInStack(lyrID) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var list = new ActionList();
var reference = new ActionReference();
var reference2 = new ActionReference();
reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
descriptor.putReference( s2t( "null" ), reference );
reference2.putIndex( s2t( "layer" ), 4 );
descriptor.putReference( s2t( "to" ), reference2 );
descriptor.putBoolean( s2t( "adjustment" ), false );
descriptor.putInteger( s2t( "version" ), lyrID );
list.putInteger( 2 );
descriptor.putList( s2t( "layerID" ), list );
executeAction( s2t( "move" ), descriptor, DialogModes.NO );
}
Copy link to clipboard
Copied
Thanks sir but I am using photoshop cs3 and this script is giving error 1243: Illegal argument -argument 2 -numeric value expected , line 37> descriptor.putInteger(s2t("version),lyrID. This might be working fine in new photoshop versions.
Copy link to clipboard
Copied
It appears that CS3 doesn't like swapping out the layer ID integer value for a variable. Yes, it does work in newer versions.
Copy link to clipboard
Copied
Try this. You need to start with the layer you want to move selected.
#target photoshop
var doc = activeDocument;
var moveLay = doc.activeLayer
var curLayer
var targetLay
goThroughLayers (doc);
doc.activeLayer = moveLay;
moveLay.move (targetLay, ElementPlacement.PLACEBEFORE)
function goThroughLayers(parentLayer){
for(var i=0;i<parentLayer.layers.length;i++){
curLayer = parentLayer.layers[i];
doc.activeLayer = curLayer;
if(curLayer.typename =='LayerSet'){goThroughLayers (curLayer)}
else{
if(curLayer.name=='LOGO'){
targetLay = curLayer}
}//end else
}//end for loop
}//end function
Copy link to clipboard
Copied
Thank you so much sir. Its working perfectly according to my requirements. Thanks for the big help ❤️