5 Replies Latest reply on Jul 23, 2013 6:34 PM by Mingrl88

    Get File Name when importing individual images

    gimbal

      Title

      Get File Name when importing individual images

      Post

      Hi, when you import a Folder of images, the Import Dialog allows you to:

       

      - import an image into a Container field

      - import the file name into a Text field

      - import the file pathe into a Text field

      - import a thumbnail into another Container field

       

      Great. But I have a button on a layout next to a container field that says "Import Picture". It runs the "Import Picture" script step, which lets the user import a single image. How can I script it so the file name of the picture the user chooses to import goes into a text field?

       

      Any ideas? Thanks in advance.

       

      Using FMP9 Advanced on Mac OS X 10.5.5 on a MacBook Pro 17" 2.33 GHz.

        • 1. Re: Get File Name when importing individual images
          Orlando
            

          Hi gimbal

           

          This will all depend on how your store the image 

           

          When you import in image into a container field as a reference you can get all of that information by referencing that field in a calculation. The result of the calculation will look like this:

           

            size:602,508

            image: Picture.png or image: Projects/pictures/Picture.png if the image location is on the same volume as the db.

            imagemac:/MAC OS X/Users/yourname/Images/Picture.png

           

          Note if its not an image and an actual file instead the results will be:

           

            file: Picture.png

            filemac:/MAC OS X/Users/yourname/Images/Picture.png

           

          However if you are storing the file directly into the container you will only see the file name

           

            Picture.png 

           

          If you want to extract these values when referencing an image you can use the GetValue function and specify the line you want to extract and remove the prefix, so for File Name you would do the following in a calculation or Set Field script step.

           

            RightValues ( 

              Substitute ( GetValue ( ContainerField ; 2 ) ; [ ":" ; "¶" ] ; [ "/" ; "¶" ]  ) 

            ; 1 ) 

           

          And the the location:

           

            Substitute ( GetValue ( ContainerField ; 3 ) ; "imagemac:" ; "" )  

           

          However if you want to get the same information when you are storing the image of file into the database then you can use a few script steps to, as you most likely currently do, insert the image into the container. but modify it slightly to first store it as a reference, use the calculations above to set a couple of text fields and the insert the image again using the filepath, but this time inserting the picture.

           

          Something along the lines of:

           

            #  

           

            Go to Field [ TABLE::container ] 

            Insert Picture [ Reference ] 

            Set Field [ TABLE::FileSize ; Substitute ( GetValue ( TABLE::container ; 1 ) ; "size:" ; "" ) ]  

            Set Field [ TABLE::FileName ; RightValues (  Substitute ( GetValue ( TABLE::container ; 2 ) ; "/" ; "¶" ) ; 1 ) ] 

            Set Field [ TABLE::FilePath ; Substitute ( GetValue ( TABLE::container ; 3 ) ; "imagemac:" ; "" ) ] 

            # 

            # Now you insert the file into the databsae.

            Set Variable [ $FilePath; Value: GetValue ( TABLE::container ; 3 ) ] 

            Go to Field [ TABLE::container ] 

            Insert Picture [ “$FilePath” ] // maker sure to uncheck 'As reference'

            # 

           

           

          Notice the calculation for the $FilePath variable does not remove the "imagemac:" prefix, this is because you need this in the path for the Insert Picture function 

           

          I hope this helps and do ask if anything is unclear.

          • 2. Re: Get File Name when importing individual images
            gimbal
              

            Orlando, thanks for the reply.

             

            I am storing the image in FileMaker, not a reference, and all I want to do is store the filename whenever anyone imports, or changes an image, so that everyone can see it.

             

            Just to see, I created a Calculation field, result as text, with:

             

            GetValue ( ContainerField; 1)

             

            And that works! It returns the original filename of the image that is imported. Is there any reason not to just use this? I noticed that when you export the contents of a container field, FileMaker offers to save the file with same name as when it was imported, so that information must be accompanying the image and stored in FMP somewhere! So even though I didn't use the import as reference script steps, thanks!

            • 3. Re: Get File Name when importing individual images
              raybaudi
                

              Hi gimbal

               

              "I am storing the image in FileMaker, not a reference, and all I want to do is store the filename whenever anyone imports, or changes an image, so that everyone can see it."

               

              AND

               

              "Is there any reason not to just use this ?"

               

              Yes, there is...

               

              The file will became quicly so big that you'll re-think about this.

              • 4. Re: Get File Name when importing individual images
                gimbal
                  

                Thanks Daniele,

                 

                I'm not concerned about file size. I was only concerned with how to display the filename of an image stored in a container. Problem solved. thanks.

                • 5. Re: Get File Name when importing individual images
                  Mingrl88

                       Hi All, 

                       I have been able to get rid of the dreaded ".jpg" file extensions in the field name with a simple find/replace script. However, I am trying to do this without dialog and when the find/replace happens it still needs someone to say "yes go ahead and replace all". Is there a way to tell it to do this? I have been playing around with error messages but that isn't really what is going on. The REALLY annoying thing is that there doesn't seems to be a problem. it seems to figure it out and find/replace correctly but it makes an obnoxious sound after which when I do it with the dialog on seems to be when it is asking for permission to find/replace and you hit cancel then it pops up with "Script canceled do you want to continue"

                        

                       Help please!