14 Replies Latest reply on Sep 5, 2014 11:32 AM by flamecoder

    Using Containers

    flamecoder

      Title

      Using Containers

      Post

           I'm looking to insert png images into a container field. Our older db inserted the image with a script but at over 37 thousand records the db is now 7 gb. I have the png files stored on a server in a good file path structure and naming convention. What I'd like to do is store a reference where the image is located at. Some things to consider for implementing the container...

           1.The image will not be in this location when the path is supplied for insertion. Is there anyway to give the path and when the file exists it will be displayed? I get an error that file needs to exist to complete the insert command.

           2. Also is there anyway the path can be built on the fly to display image? If I should ever have to relocate the folder structure to another server a simple change to beginning path would change all records. For example the path "AppleCore/CreativeServices/Completed-JobFolders" will be the same for all records until a server change. The path after "Completed-JobFolders" will always remain the same for that record no matter what server it is moved to.

           AppleCore/CreativeServices/Completed-JobFolders/CI-Numbers/CI000000-CI019999/CI012000-CI012999/CI012014-RollingStones/CI012014-Front.png

           2. The path must work in both Mac and Win for locating the image to display. Will I need to create different paths for each platform? For example does it need to start with imagemac:/ or imagewin:// or is this just an insertion requirement. How does Relative path work?

           3. What is "Store container data externally" for. Is this something I should look into? Also Secure or Open storage.

           4. The FM script to insert the image is being executed by AppleScript outside of FM with "do script" that builds the path for the image. There is no user intervention for inserting images.

           5. Is there any other way to just display an image from a file path?

        • 1. Re: Using Containers
          philmodjunk

               1. This description of your issue has me scratching my head. If "The image will not be in this location when the path is supplied for insertion." where is the file at that time?

               One guess is that you are inserting the file on a local computer and need to move the file to that other location. This can be scripted so that a user inserts or drags and drops the file into the container and then the OnObjectModify trigger performs a script that a) uses export field contents to export the file to the folder on your server and b) then re-inserts the file from this new location with "store a reference" specified.

               But I'm making a lot of guesses here about what you want to do.

               With regards to your other questions, what version of FileMaker are you using? If you are using version 12 or newer I suggest researching the "external storage" option that can be specified for a container field in these newer versions to see if that option will work for you. It would make managing your container field files much easier in many respects.

               2) The same path usually can't work on both platforms. The path on a mac starts with a volume name and the path in windows starts with a drive letter. This is one of the issues resolved with external storage. In older systems, you sometimes have to either use two container fields, one with the mac file path and one with windows or a calculation field with container as the result type might be used to extract the filepath from the actual container field and modify it to be either the Mac or windows version of the file path. And there's also a third party product SuperContainer to evaluate as the solution here.

               4. That won't work in windows and why use an Applescript for something easily done without AS?

               5. Supercontainer, Open URL, the Web Viewer....

          • 2. Re: Using Containers
            FentonJones

                  

                 The short answer is that you can show an image using only a calculation field, with the result of the entire file path (from beginning to end). Take a look at what the path is (as FileMaker sees it) now; then reproduce it with such a calculation field.
                  
                 To begin with, it starts with the system: 
                 Case ( Abs ( Get ( SystemPlatform)) = 1; "imagemac:/"; "imagewin:/" )
                  
                 Then you'd need whatever (on a Mac; I imagine Windows has something similar) whatever the "volume" is. Then the "stays the same" folder paths. Then the path data which is unique to a record.
                  
                 When you get the calculation return the correct path (from the system you're on) the image will show (when the result is "Container"; you can create a dupe of the field, with result "Text", to see it. These are both (all) Unstored fields.
                  
                 Probably the most convenient way to do things that change for all files would be to put them in a 1 record "Global" table (or whatever you want to call it). So you can manually change it when needed, without having to change the calculation. You would need however to protect that table (no deleting it, no creating 2 records, etc.).
                  
                 You say something about using an AppleScript to run a FileMaker script with "do script". Are you having that run when you enter an image file into a folder?
            • 3. Re: Using Containers
              flamecoder

                   Most often the real world is more complex than the conceptualize world. I'm coming from a manufacturing company that has a department of 20 artists. They have a workflow that works good and doesn't need changed. I just need to slow the growth of the db and add additional features as I create this new db. When a job is worked on, it is created new or pulled from storage location for a revision to artist's individualized work in progress folder. After completion a checkout process (AppleScript Objective C application) is run twice a day on completed jobs for quality assurance. Only a small portion of dozens of tasks are to interact with the FM database. 99% of data is automatically added or changed in database with AS when programs are run for other reasons. Macs do all the adding of data while pcs in other departments just view data. A versioning backup runs during the night on the work in progress folders and automatically places job in storage location where I want the db to look for the pgn image.
                   I'm using FM 12 with FMS 12. The calculation field sounds like a good idea and I briefly looked into this but don't understand how the image is displayed in the field. I'm a programmer so understand building the file path but asking the calculation field to display an image isn't working for me. Breaking this down to make it simple suppose I have a png image on my desktop. I have a calculation field that returns "imagemac:/" since I'm working on a mac for now and a text field holds the path to this image. Somewhere I concatenate the strings to form the complete path but what displays the image?

              • 4. Re: Using Containers
                FentonJones

                Sorry I missed this post. I've been a little ill the last few days. The short answer is that what shows the a calculation, who ends up the total "imagemac:/" (or PC, "imagewin:/") path to the imagine, with the result "Container" as its type choice (at the bottom right of the calculation window). It is similar to a plain field with the same result of "Container"; either shows the image.

                • 5. Re: Using Containers
                  flamecoder

                  Setting the result to "Container" was what I was missing. Thank you and hope you are feeling better!!

                  • 6. Re: Using Containers
                    flamecoder

                    This idea is coming along great but I now need to get rid of the text if the file is missing. The way I have it now it looks for all sides and displays any found in the folder. Products can have many imprinted sides but most will not always have all sides imprinted. I have calculation fields for each side as (Image_Platform & Image_File_Path & "-Front.png"). The "-Front.png" changes for particular side so calculation for Reverse image contains "-Reverse.png". I need to test if the container has a value and if not I was thinking just to supply a path to a png image made of the same grey as the background. I'm not sure how to add a conditional statement to this calculation...

                    • 7. Re: Using Containers
                      philmodjunk

                      IsEmpty ( YourTable::ContainerField )

                      will be True if the field is empty

                      • 8. Re: Using Containers
                        flamecoder

                        I was previously trying use IsEmpty function but I don't see how to first try to display the file then do the test.

                        I get this error when I have two lines of code...

                        • 9. Re: Using Containers
                          philmodjunk

                          Remove the first line of text and just keep the If function.

                          • 10. Re: Using Containers
                            flamecoder

                            ummm.... it will always be empty to start with before the first line. To refresh you on this thread I'm displaying these images on the fly and they are not stored. The field is a calculation and returns a container. I'm thinking I need to supply the path for the image then do the test to see if it has anything then if empty supply a path to a default blank image.

                            • 11. Re: Using Containers
                              philmodjunk

                              Try it this way:

                              If ( Not IsEmpty ( Image_File_Path ) ; put your original file path calculation here )

                              This will return nothing and should show an empty container field when Image_File_Path is empty. If, for some reason, the value in Image_file_Path is not empty when there is no image, you'll need to set up a different test of the value of this field.

                              • 12. Re: Using Containers
                                flamecoder

                                Tried above and get the same result as before. The IsEmpty function seems to always be returning false weather it displays the image or can't find the image. I am feeding it a file path and perhaps that is why it is always not empty??? I need to find a way to tell if there is an image being displayed or not.

                                • 13. Re: Using Containers
                                  philmodjunk

                                  Well that explains your original result. It appears that Image_File_Path is never empty even when the file path produced does not "point to" an actual file.

                                  I had wondered why you weren't getting an empty result in the original version as I could see that the "do not evaluate if all referenced fields are empty" check box was selected.

                                  Is there any way to tell, from the contents of Image_File_Path that the actual image does or does not exist?

                                  If not, you'll need to use a script. The script can use Insert File and your computed file path to insert a "reference" to the file. This has an identical result as your calculation field, but should leave the field empty when there is no such file to insert.

                                  • 14. Re: Using Containers
                                    flamecoder

                                    I resolved this by adding a checkbox field with a value list of "Show" for each side. Then for on the fly calculation I did this...

                                    If ( Image_Reverse_Check = "Show" ; Image_Platform & Image_File_Path & "-Reverse.png" ; Image_Platform & "PathToDefaultGreyImage" )

                                    I can set the checkbox with applescript while adding or updating the record since validating if a file exists can be done at that time. I can also manually toggle on and off the checkbox which is a good thing.