Q1: Yes, you can import multiple images from a folder.
So if you have all the images for a contact arranged in a folder, you can script the process for the user to select the folder (Get Directory script step) and then import all images from that folder. The script could then associate all the imported image records with the contact record.
Q2: No, initially there is probably no reason to store photos in a separate file. However, you may consider external file storage for the container. Have a look at Storage options for the container field (Store container data externally).
Thank you David for your input.
I tried to do this manually first. (File>Import>Folder)
Problem is I import the images to the container field but then they are not related to any contact.
Am I missing a field in Table 1 for this?
After importing, you would need to set the foreign key to link those new records back to the contact. When doing this manually, you would probably use a Records > Replace Field Contents…
If you scripted this, the pseudocode would look like:
// Starting on a Contact record
Set variable to the primary key of the contact
Go to the images layout
Get the directory of the images folder required
Import images from the folder
Replace field contents to set field for the foreign key (contact) using the variable
Go back to the original layout
This will be my first script. I will have a try at it tonight...
I got it working after some trial and error. Thank you for pointing me in the wright direction.
I now have an additional question.
I have not specified a directory which contains the images.
So the user has to browse trough the entire computer.
Would it be possible to open the browse window to a specific directory and let the user select a subdirectory? Additionally can I use that directory name for the name field in my contact record?
The Get Directory script step allows you to define a default directory (where the search starts).
You will have to specify the whole file path or use something like Get ( DesktopPath ). And of course we are assuming that the directory in question will exist on the user's computer.
I don't quite understand what you mean by "Additionally can I use that directory name for the name field in my contact record?". If you mean can there be a field in the contact record that specifies a file path to their directory, then yes you can. And you could use that field value as the default file path. Or I suppose you could also use that to set the variable and automatically import from there. You would need some error trapping in there for the case where the file path does not exist.
I think I am doing something wrong.
I tried using the function Get(FilePath) then the script imports the images in this folder but I don't get a dialog to let the user select a subdirectory.
I also tried Get(DesktopPath) but then the script seems to assign all previous image imports to this record.
Here is the script I used, am I missing something?
For the second question:
I have a directory d:/models which contains subdirectories named for example Anna, Tim, Louise
These directories with the names contain the persons photos.
I would like the script to store these directory names in my field for the contacts name upon import of the images.
This way the user does not have to key in the contacts name in filemaker, but gets it automatically upon import of the images.
OK, first, please ignore all reference to the Get Directory script step. I see in your first post (and from your script screenshot) that you are using FileMaker Pro 13. The Get Directory script step is a FileMaker Pro 14 new feature. Could be a reason to upgrade?
Where you are setting the variable in the third line, you would only need: "filewin:/D:/models/"
To direct the import to a specific folder for a model, you could use: "filewin:/D:/models/" & MODELS::subdirectoryField
But you would need to set that before you leave the layout, so move the third script step up.
You are looping through the records to set the foreign key. You can do this for the imported found set in one step using the Replace Field Contents script step.