Creating and moving an artLayer inside "active" layerSet

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

User avatar
StoryCave
Posts: 20
Joined: Wed Sep 21, 2016 2:14 pm

Creating and moving an artLayer inside "active" layerSet

Post by StoryCave »

Hi guys,

Another issue, I'm using the StoryCaveCam.jsx script to create an artLayer within a layerSet in this folder structure :
SCTFolder1.jpg
SCTFolder1.jpg (5.75 KiB) Viewed 15279 times
The script creates the layer like this :
SCTFolder2.jpg
SCTFolder2.jpg (5.81 KiB) Viewed 15279 times
But if I run the script with multiple folders and because I use the index of the top layerSet, it only creates the CAM layer in the top group :
SCTFolder4.jpg
SCTFolder4.jpg (8.03 KiB) Viewed 15279 times
I would like the script to create that layer inside the "active" layerSet below the Dialog group like this :
(can't add a third image)
>SQ_00_SH_000_000
>>Dialog layerSet
>>CAM
>>drawing

I could only find the active.artLayer method and no "active.layerSet"... I guess this would probably fix the issue.


that's how the code works :

Code: Select all


var newCamLayer = docRef.artLayers.add()
newCamLayer.name = camName
newCamLayer.move(docRef.layerSets[0], ElementPlacement.INSIDE)
docRef.activeLayer = newCamLayer
For the pIacement of the layer I also tried this :

Code: Select all


newCamLayer.move(docRef.layerSet.layerSets[0], ElementPlacement.AFTER)

and

newCamLayer.move(docRef.layerSets[0][0], ElementPlacement.AFTER)
But can't make it work.

Also and lastly, is there a way I could move the backgroundLayer at the bottom of the main layerSet (SQ_00_...) ?

Thanks for your help, I hope this isn't too confusing.

K.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Creating and moving an artLayer inside "active" layerSet

Post by Kukurykus »

To add a layer inside active layerSet (inside other layerSet when that "inside layerSet" is selected):

Code: Select all

activeDocument.activeLayer.artLayers.add()
Doing the same by index:

Code: Select all

activeDocument.layers[0].layers[0].artLayers.add()
It's how to move a background (changed first to normal layer) to the bottom of top layerSet:

Code: Select all

if ((btm = (lyr = activeDocument.layers)[lyr.length - 1]).isBackgroundLayer) btm.isBackgroundLayer = 0
btm.move(lyr[0], ElementPlacement.PLACEATEND)
User avatar
StoryCave
Posts: 20
Joined: Wed Sep 21, 2016 2:14 pm

Re: Creating and moving an artLayer inside "active" layerSet

Post by StoryCave »

Thanks Kukurykus ! you're saving the day again ;)

One little thing, I'll use the transformed BackgroundLayer rather than the new artLayer I created, though I couldn't change the name and its properties, I tried :

Code: Select all


if ((btm = (layerBg = activeDocument.layers)[layerBg.length - 1]).isBackgroundLayer) btm.isBackgroundLayer = 0
btm.move(layerBg[0], ElementPlacement.PLACEATEND)
activeLayer.name = backgroundName // this is a variable inside my reference script
activeLayer.allLocked = true;
it takes the activeLayerSets as the activeLayer instead of the BackgroundLayer that was transformed, any clues ?

Cheers.

K.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Creating and moving an artLayer inside "active" layerSet

Post by Kukurykus »

If I understand well then you don't have background but simple layer instead of bg, and that layer has some name.

Is that layer on the bottom? I mean last available item, below other folders and layers?
If so I tried it and it moved last layer to the location pointed in script.

Anyway when I used your script, in the part you commented (slashes) it wanted to change the name of a folder where a script moved a background/layer to, not the sole bg/layer.


I'm not sure what you are asking for. The best would be if you said that once again other words or just made screenshot like in first post, so I can imagine it proper way, and then help if I'll know how of course...
User avatar
StoryCave
Posts: 20
Joined: Wed Sep 21, 2016 2:14 pm

Re: Creating and moving an artLayer inside "active" layerSet

Post by StoryCave »

Hi Kukurykus,

The script you used was the old one, I've just updated it with your code to transform the original Photoshop "Background" Layer into "Layer 0", but can't rename Layer 0.

Basically, is it possible to just move the original backgroundLayer to the bottom of the folder ?

or

Deleting the original backgroundLayer and using my old script with the "background" layer creation ? This one seems like a waste of resource but I couldn't delete it myself.

Thanks for your help again ;).

(I'm now ticking the "Notify me when a reply is posted" box, that's why I completely missed your messages)
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Creating and moving an artLayer inside "active" layerSet

Post by Kukurykus »

Okey I got it.

For an example I made beside background a new folder where I put another folder, so at the beggining I had empty subfolder in main folder and beside all there was also a background (not in any of the above). Try the following to see the result is what you expected (it should work also in the case from your picture):

Code: Select all

if ((btm = (lyr = activeDocument.layers)[lyr.length - 1]).isBackgroundLayer) nme = btm.name,  btm.isBackgroundLayer = 0
btm.move(lyr[0], ElementPlacement.PLACEATEND); (bGl = (bGn = lyr[0].layers)[bGn.length - 1]).name = nme, bGl.allLocked =1
User avatar
StoryCave
Posts: 20
Joined: Wed Sep 21, 2016 2:14 pm

Re: Creating and moving an artLayer inside "active" layerSet

Post by StoryCave »

Well, this is just perfect, thanks a lot Kukurykus :mrgreen:
I'll definitely give you massive credit on my thank you list.

Back to your first reply :
To add a layer inside active layerSet (inside other layerSet when that "inside layerSet" is selected):
activeDocument.activeLayer.artLayers.add()

Doing the same by index:
activeDocument.layers[0].layers[0].artLayers.add()
I've tried both options yet it still creates the CAM layer in the top layerSet, but also inside the LayerSet's layerSet, here's the example I'm trying to figure out :
Cam_1.jpg
Cam_1.jpg (20.14 KiB) Viewed 15144 times
Because of the index docRef.layerSets[0], it creates it on the top layer, I don't mind if it's before the dialog layerSet, but if it could be inside the active layerSet that would be awesome.
Cam_2.jpg
Cam_2.jpg (21.38 KiB) Viewed 15144 times
What happens when there are multiple layerSets and decide to go back inside one of them to add a CAM layer ?
Cam_3.jpg
Cam_3.jpg (26.2 KiB) Viewed 15144 times
All these scripts that I'm trying to make are based on actions, here's the action for CAM if recorded with the scriptListener but doesn't show any code I could use :

Code: Select all


var idPly = charIDToTypeID( "Ply " );
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idActn = charIDToTypeID( "Actn" );
ref2.putName( idActn, "Camera" );
var idASet = charIDToTypeID( "ASet" );
ref2.putName( idASet, "STBD_Tools" );
desc4.putReference( idnull, ref2 );
executeAction( idPly, desc4, DialogModes.NO );
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Creating and moving an artLayer inside "active" layerSet

Post by Kukurykus »

You can't record played action by ScriptListener. You can record only manual operations. Anyway underneath I'm posting a code I was asked for:

Code: Select all

aL = (aD = 'activeDocument') +'.activeLayer', bol = true, arr = []

while(bol) aL += '.parent', String(AL = eval(aL)).slice(1, 9) != 'LayerSet' ? bol = !bol : arr.push(AL.name)

aDl = aD + l = '.layers', n = arr.length - 1;

(function set() {
for(i = 0; i < (evl = eval(aDl)).length; i++) {
if (evl[i].name == arr[n]) {
aDl += '[i]' + l, n--, aD += l + '[' + i + ']'
if (n > -1) set(); break
}
}
})()

if ((btm = (lyr = activeDocument.layers)[lyr.length - 1]).isBackgroundLayer) nme = btm.name, btm.isBackgroundLayer = 0
btm.move(aD = eval(aD), ElementPlacement.PLACEATEND);(bGl = (bGn = aD.layers)[bGn.length-1]).name = nme, bGl.allLocked=1
You have to select some layer in some set, only then it will work, otherwise something unexpected may happen, example:

ImageImage
User avatar
StoryCave
Posts: 20
Joined: Wed Sep 21, 2016 2:14 pm

Re: Creating and moving an artLayer inside "active" layerSet

Post by StoryCave »

Thanks for your feedback, I've tried the code but only got an "undefined" (with the whole code) or "set()" (after removing the backgroundLayer code), the idea is exactly to select anything inside the main layerSet (ex. SQ_00_SH_000_XXX).
I'm also trying to understand the code as it's now getting more advanced :oops:
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Creating and moving an artLayer inside "active" layerSet

Post by Kukurykus »

You shouldn't remove backgrounLayer code:

Code: Select all

if ((btm = (lyr = activeDocument.layers)[lyr.length - 1]).isBackgroundLayer) btm.isBackgroundLayer = 0; nme = btm.name
btm.move(aD = eval(aD), ElementPlacement.PLACEATEND);(bGl = (bGn = aD.layers)[bGn.length-1]).name = nme, bGl.allLocked=1
because all code which is over it will be useless, so you're rigth it will result "undefined". First part of code is to check name and position of selected layer. Only then backgrounLayer code move background at the end of folder which some layer was selected. If that was some subset selected of some set then background will be moved to end of that set (which selected set is inside of).

I tried now it when backgroundLayer is already changed to normal layer and found it doesn't work so I changed backgroundLayer code a little. I moved nme - btm.name at end of its codeline and preceeded that with a semicolon (the code at the beggining of this post is already corrected).


Perhaps I don't understand, if you use my example (that from first image of previous post) and then play the code I used in that post is it working? I mean will it move background layer to the parent of selected layer/subset ? Please make some new screenshots to help me understand if I don't get something you mean... (btw awesome emotion graphics you made!)