Here I was trying out from an example UXP plugin, and I assigned this function to the second button “WoopsYeah”, which worked well until I add “.name” to the red rect place.
It seems to have a stop at Row 24 if “.name” is added and Const b would not be printed, albeit Const c is not used.
And If I remove “.name”, Const b will be printed.
So why I could’t just directely get the chosen layer’s name (I test several ArtLayer attr but all of them lead to the same problem) or did I miss something?
What did you get without a .name
? I suspect there’s no active layer and you should see an error in console while trying to access name
of undefined
I got “15” as printed in “Output”, that went well. And I’m pretty sure I do have selected one and only one artLayer so there should be no way of app.activeDocument.activeLayer returnning undefined.
What is c
without a .name
?
Nevermind
activeDocument
does not have a property named activeLayer
. That’s what I was talking about. You should get undefined
for c
without a .name
.
Property you should use is activeLayers
, which is a collection (array of layers). So if you want only one first active layer, it should be:
app.activeDocument.activeLayers[0].name
But I strongly suggest to have some checks if there’s an active document and/or layers
Maybe something like this (would need to test):
app.activeDocument?.activeLayers[0]?.name
Oh my! I got screwed.
You are right, activeLayers[$] do help. “activeLayers” is not mentioned in this 2020 PS.JS doc and I don’t know why.
I suppose for UXP you should be using web version of docs, which is kinda updated more or less frequently. Definitely more than PDF
This PDF shows the JavaScript Reference for CEP extensions, which is the outdated technology.
As @Karmalakas said, for UXP you should check the web documentation. (I don’t think UXP docs even exist in PDF format)
I was wondering if that PDF could be for CEP