9 Replies Latest reply on Mar 5, 2012 12:30 PM by philmodjunk

    Using a script to import jpg images to container field

    autumnsky

      Title

      Using a script to import jpg images to container field

      Post

      I'm a little stuck.

      I have a script that exports jpg images out of a container field. The script creates a directory on the desktop called "Export_Images" and then loops through the records exporting a container field and naming each exported file: RecordID &".jpg"  

      Once completed, the Export_Images directory contains series of files that look like this:

         10000.jpg

         10500.jpg

         etc.

       

      I now want to import these images back into a clone of the database (BTW, I first import all the data fields into the clone database. So records with the correct RecordID are all created once I start the image import script.) Here is my routine for importing the jpg images back into the container field for each record:

           Go to Layout[TargetLayout]

           Go to Record/Request/Page [First]

        Loop

           Set Variable [$filepath; Value "filemac:" &  Get ( DesktopPath ) & "Export_Images/" & RecordID  & ".jpg""]

           Go to Field [z_TargetContainer]

           Insert Picture ["$filepath"]

           Go to Record/Request/Page [Next; Exit after last]

        End Loop

        Exit Script[]

       

      When I dump the variable $filepath into a field, the path and filename seems correct:

         filemac:/Macintosh HD/Users/UserAccountName/Desktop/Export_Images/10000.jpg

      but when executing the script,  I receive an error message: The file "10000.jpg" could not be found and is required to complete this operation.  What am I doing wrong? Sorry if this post seems confusing and thanks for your time and help.

        • 1. Re: Using a script to import jpg images to container field
          philmodjunk

          how is "recordID" determined? Have you checked to be sure there's a  file in the folder named 10000.jpg?

          ("RecordID" can be an auto-entered serial number field, but there's also a function: Get (RecordID) that some people try to use in place of the serial number. That second option doesn't usually work well when importing data into a clone, so I am checking on that possibility. )

          • 2. Re: Using a script to import jpg images to container field
            autumnsky

            Q1: Yes, there is a file in the folder named 10000.jpg (it is actually named IMG_10000.jpg   I simplified the file name in my earlier post)

             

            Q2 When the record is originally created, it is an auto-entered serial number field  (On Creation next serial number IMG_10204 increment by 1). However, in this case, I am importing data from a data set and recordID is copy from that dataset  When checking each record after the data import, the recordId is imported correctly. The data import script seems to work perfectly.

            The problem is the image import script, which follows after data import.

            See 1st post) After creating the variable $filepath, I dumped it into a field for testing. The variable seems to get the correct pathname and recordID:

                 filemac:/Macintosh HD/Users/charette/Desktop/Export_Images/IMG_10000.jpg

            But for some reason the Insert Picture ["$filepath] command chokes in the script. I know that when I specify the Insert Picture file manually in the script through the Add File button, it puts the term "image:" in front of the pathname/imagename.jpg.

            (e.g. image:Export_Images/IMG_10000.jpg)

            Is the term "image:" important to have in the pathname? If so, how is that to be structured? Thanks.

             

             

            • 3. Re: Using a script to import jpg images to container field
              philmodjunk

              You need imagemac: (all lower case) not filemac: The two different tags depict two different methods of inserting a file into a container. Use imagemac with insert picture and file: or filemac: with insert file.

              • 4. Re: Using a script to import jpg images to container field
                autumnsky

                Ah! It works Perfect!!!

                Many thanks, Phil, it seems so logical now that I see it. A follow up, question. What gets inserted at the front end when importing to a PC?

                • 5. Re: Using a script to import jpg images to container field
                  philmodjunk

                  The drive letter is the first item in the file path. You can see the text entered into any "store a reference" container field by using Getastext ( container field) in the data viewer (Filemaker Advanced), or you can use a calculation field set to return text with just the name of the container field entered into it.

                  This is often a useful way to debug issues with file references stored in containers--especially if you have both mac and windows clients sharing the database.

                  • 7. Re: Using a script to import jpg images to container field
                    philmodjunk

                    Hmmm, you may have been asking what to use in place of "imagemac:", if so, use "imagewin:"...

                    • 8. Re: Using a script to import jpg images to container field
                      autumnsky

                      Actually, both answers are helpful. I seldom work in a Windows environment but I will have clients using this solution who will. I will need to work on some logic for these scripts that will work in both environments. For example, when creating the directory that gets placed on the Mac desktop is had to use an Apple Script

                          Perform AppleScript ["do shell script "mkdir -p ~/desktop/" & quoted form of "Export_Images"]

                      Obviously, that will not work on a Windows Client Wink

                       

                      Cheers, Phil. Have a great day. -- LC

                      • 9. Re: Using a script to import jpg images to container field
                        philmodjunk

                        Yes, FileMaker is unable to create new directories on either platform. One method is to use a system script such as Apple script and then you end up with one system script for Mac systems and a different script (VB Script, batch file, etc.) for windows platforms. It's possible to create and store the script in a text field, then use export field contents to export the script and use send event to open and run the script.

                        Another options is to acquire a plugin that offers the ability to create folders and use it. MooPlug is a windows only free plug in that can create folders if I remember correctly.

                        The draw back to using a plug in is that there is no guarantee that it will be properly supported by the developer if a new release of FileMaker is not compatible with it.