I am trying to get all layercomps names. Since this is still missing in UXP API.
I created a simple extendedscript to get this list and write it to file.
Currently I write this list to the temp folder under: $.getenv(“LocalAppData”).
%LocalAppData%\Temp\layerscomps.txt.
I created an action to run this script.
In my UXP plugin I run this action via batchplay.
The problem I am facing, in UXP, is that I can’t read from the temp folder unless the user specifies it with the file picker, which is not an option.
How can write to a file which is accessible to the UXP plugin?
Or, how can I write to the UXP plugin folder in my extendedscript which would mean passing the UXP plugin path to the script/action, which I think it is not possible?
If you’re dealing with arrays, you might consider using a JSON files instead. Wouldn’t be any issues figuring out how to parse lines. Sorry, but I don’t have any example on how to parse such structure.
I finally got it but it is a cumbersome solution which I will temporarily use until adobe adds this support.
It goes like this:
Preparation:
Prepare an extendedScript which generates a list of all layerComps and writes it to tmpFile.
tmpFile name is read from the layer[0] in the current doc.
Create a batchPlay function to run this script
Usage:
Generate a new layer whose name equals to the plugin TemporaryFolder. this is now layer[0].
Run the batchPlay action to run teh extendedScript.
Read tmpFile (which was generated in TemporaryFolder by the extended script)
You could write the layer comp names to an array and save the array as a global variable in your plugin’s JS. No file writing necessary and easily accessible. This assumes you’ll be using the names during the current Ps session. If you need the names for another Ps session, then the getDataFolder() option should work.
How do you write that global variable?
The layercoms are generated in an external extendedscript file?
Can you show a simple exampe of write this variable and then read it?
This establishes the variable as an array. As long as you don’t put this declaration inside a function, it will be available throughout your JS, both inside and outside the function brackets, { }. This is what makes it a “global” variable.
You then need to use the JavaScript .push() function to add data values (layer comp names, in your case) to the array as they are generated.
However, I think your other issue is using extendScript to get the layer comp names. As mentioned elsewhere in this thread, using ExtendScript inside UXP is not a good idea. You should use Alchemist instead. It has a “compsList” property in Documents that looks like it supplies the information you’re looking for. You could iterate through the “compsList” arrary from Alchemist to extract their names and then “push” them into your array, which only contains these names.
This is the “getter” for this “compsList” Document property. NOTE: I don’t think you need the “_id: 219” part as it would be document specific for my document. Don’t include that.
The
console.log(result);
will display the results in the UXP Developer Tool console.
It’s usually an array of objects, and you’ll need to deconstruct based on what you get in order to find the “title”, which is the name for a particular layer comp. The UXP Developer Tool will show you the “result” via console.log and you can keep clicking the arrows on the left to locate the path to the “title”.