Copy link to clipboard
Copied
Hello, I hope someone can help me in a project,
to resume what I am trying to achieve is create an script which can place an image from a folder
with several images and place one of them depending on name and based in a text layer,
(auto select image based in name) example:
File 1:
Layer text " Cat"
Import from folder any image with the "cat" in the name (big cat.png)
File 2:
Layer text "Dogs"
Import from same folder any image with the "dog" word in the name ( red dog.jpg)
File 3:
Layer text "All Mouses"
Import from same folder any image with the "Mouse" word (gray mouse.jpg)
I used several scripts to cut the words, extract text etc so not sure if is possible to create something like that, I apreciate any welp or light you can bring to this idea.
I hope is not an impossible task to do, and please appologize I am a begginer in cooding, so please appologize if my question is stupid. THank you for your help.
Copy link to clipboard
Copied
Change your text layer content to singular name (so without 's' at end), that you look for in file names:
c = activeDocument.activeLayer.textItem.contents
f = function(v){return RegExp(c, 'i').test(v.name)};
(fls = File('~/desktop/yourFolder').getFiles(f)).length
&& (sTT = stringIDToTypeID, dsc = new ActionDescriptor(),
dsc.putPath(sTT('null'), fls[0]), executeAction(sTT('placeEvent'), dsc))
btw you did not answer my question: Jan 21, 2022
Copy link to clipboard
Copied
Thank you very much for your help and for be so kind, I will try this code ASAP I guess is a good start,
My main goal here is to find a way to match some of the text in the layer with some of the text in the JPG files names in a folder, (automate the match in some way for a bunch of PSD files and JPG images)
I mean , automate the images selection,
lets say I have many psd files with some text layer containing one or more words :
layers: ("tomato", "dog", "plant", "gold keys"...)
and have similar (not same name) JPG files in a folder to import:
( "red tomatos.jpg", "big dog.jpg", "key.jpg")
and in some way automate the process (any number of images and psd files) and make an almost perfect selection where I end with psd files with the "related" images inside,
a tomato.psd file with the "red tomatos.jpg" image placed inside next to the text layer "tomato"
a dog.psd file with the "big dog.jpg" image placeid inside next to the text layer "dog"
.... etc
(I know I can use data sets to do something similar) but I want to automate the image selection process without use data sets as I want to override the need of use "exact names",
I am trying to learn about regex but I am very slow in this process, so the code I am looking for may be able to match part of layer text with part of file's text no matter is not 100% exact to match all images. (image for some text may not be present)
Your code turn some lights to me, I guess is a good start, thank you for your help.
Copy link to clipboard
Copied
To keep 's' letters at end of some text layer conetnt and make comparing words more reliable:
RegExp('(^| |\\b)' + c + '?(\\b| |\\.)', 'i')
Copy link to clipboard
Copied
Please remember to mark a post as »Correct Answer« if it should resolve the issue.
Copy link to clipboard
Copied
While attempting to have a go at scripting this, it became apparent that a much quicker solution (for me) would be to use Adobe Bridge:
Copy link to clipboard
Copied
I didn't know I can look for text layer contents in file metadata. I created new document with only text layer containing 'dog'. The Bridge found it indeed, then I tried inexistent 'cat' and it found it too? I made last try searching for 'horse'. It wasn't inside. The second approach with a 'cat' shows this method fails.
Copy link to clipboard
Copied
Horse passed (no false positives).
Cat failed, as there is metadata containing:
application
It's a shame that it is not regex based, that would be more useful:
\bcat\b
So it is of limited use, depending on the word. Oh well.
This is as far I as got with my script, filtering on keyword dog in filename, but not able to additionally filter on text layer content.
var inputFolder = Folder.selectDialog('Select the input folder', '');
var inputFiles = inputFolder.getFiles();
for (var a = 0; a < inputFiles.length; a++) {
if (inputFiles[a].name.match(/dog/i)) {
open(inputFiles[a]);
}
}
It's a tough one for my current skill level.
Copy link to clipboard
Copied
You mean you don't know how to access content of text layer? Look into first line of my code.
Copy link to clipboard
Copied
That line works on open documents, I suspect @Stephen_A_Marsh hopes to figure out how to avoid having to open the file to get the type layer content.
Which would seem neat …
Copy link to clipboard
Copied
@c.pfaffenbichler wrote:
That line works on open documents, I suspect @Stephen_A_Marsh hopes to figure out how to avoid having to open the file to get the type layer content.
Which would seem neat …
Copy link to clipboard
Copied
I don't know why you are placing, I read the request as simply opening all files that have both a matching name and text content.
I can access text layer content of an open doc with a targeted active layer...
But no files are actually open, and even if they were, one would need to loop through all layers and find the content of text layers and match.
Perhaps filtering by reading the file list as binary or looking into metadata content for text layers etc?
Or perhaps closing any open file that does not have a text layer matching etc.
As I said, easier said than done (for me).
Copy link to clipboard
Copied
Doesn't an author say twice in first sentence of placing the images from a folder?
Copy link to clipboard
Copied
Ah your right, I went off on a tangent. You have to forgive me as English is my first language 😉