12 Replies Latest reply on Jun 20, 2014 9:53 AM by philmodjunk

    Problems setting up a script to edit a photo in a container filed.

    HenryRobinson

      Title

      Problems setting up a script to edit a photo in a container filed.

      Post

           Server OS: windows server 2008 R2 64 bit FileMaker server 12

           Client OS: windows 7 64 bit FileMaker Pro 12

           I am trying to make a Script that will do the following:

             
      •           Export an image from inside a portal to a temp folder and open it with the default program.
      •      
      •           The user can edit the file and save it.
      •      
      •           When the image was exported the database is sitting at a layout ready to continue. See image 1
      •      
      •           When the user continues it shows both the old image and the new image with an option to discard the changes or keep them. See image 2
      •      
      •           Once done you can see the new image put in the right field. See image 3

           The current script I have made almost works. The problem I am having is once I go back to edit the image I get an error message the file "?" could not be opened. (Not Found)

           At this point the image disappears.

           Script Steps

             
      •           Set Error capture [on]
      •      
      •           #set layout name for latter reference to return
      •      
      •           Set field [Cards::Variable Last layout; get (layoutnumber)]
      •      
      •           Set field [Cards::Variable Last portal row; get (activeportalrownumber)]
      •      
      •           #set location to export file
      •      
      •           set variable [$$filepath; Value: get (temporarypath) & getastext (container storage::container)
      •      
      •           Export filed contents [container storage::container; "$$filepath"; automatically open]
      •      
      •           Go to layout ["begin photo edit" (cards)]
      •      
      •           Insert File [Insert; display content; Never compress; Cards::currentphotoeditingbefore; "filepath"]
      •      
      •           Insert File [reference; display content; Never compress; Cards::currentphotoeditingafter; "filepath"]
      •      
      •           Refresh window

           when the user decides to accept the changes it runs this script

             
      •           Go to layout [Cards::Variable last layout]
      •      
      •           Go to portal row [select; no dialog; Cards::variable last portal row]
      •      
      •           Set filed [Container storage::container; cards::CurrentPhotoEditingAfter]
      •      
      •           #blank Variables
      •      
      •           Set Variable [$$filepath; Value: ""]
      •      
      •           Set filed [Cards::currentPhotoEditingAfter; ""]
      •      
      •           Set filed [Cards::currentPhotoEditingbefore; ""]

      Currently_Editing.png

        • 1. Re: Problems setting up a script to edit a photo in a container filed.
          philmodjunk

               Seems like there's a problem with these two script steps:

                 
          •           Insert File [Insert; display content; Never compress; Cards::currentphotoeditingbefore; "filepath"]
          •      
          •           Insert File [reference; display content; Never compress; Cards::currentphotoeditingafter; "filepath"]


               You appear to be using the literal text "filepath" instead of the name of the global variable: $$filepath

          • 2. Re: Problems setting up a script to edit a photo in a container filed.
            HenryRobinson

                 That was my mistake I tried to find a way to copy and paste my script but could not figure out how, so I retyped it by hand and had a typo. In the real script it is using the global variable $$filepath

            • 3. Re: Problems setting up a script to edit a photo in a container filed.
              philmodjunk

                   What are the storage options specified for Container Storage::Container?

                   Was the file inserted by embedding the image or by specifying "store a reference"?

                   Was Insert File, Import Records or Insert Picture used to insert the file into Container Storage::Container?

                   All of these details can affect what text is returned by: getastext (container storage::container)

              • 4. Re: Problems setting up a script to edit a photo in a container filed.
                HenryRobinson
                     

                          Was the file inserted by embedding the image or by specifying "store a reference"?

                     Not sure what you mean by this question.

                     In the script insert file was used because it will not always be a photo that needs to be edited. But the normal way a file will be inserted into the database will be right click paste.

                      

                      

                     sorry if my post seem a little messy still learning how to best use the forum tools.

                • 5. Re: Problems setting up a script to edit a photo in a container filed.
                  philmodjunk

                       When you select one of the Insert options for inserting a file into a container field, or use import records | Folder or use a script that inserts the file, there's a check box that appears in one dialog or another: "store a reference".

                       But if you select a file shown in a window from your OS (not a FileMaker window) and copy and paste from it, then you are embedding a copy of the file into your container field, not inserting a reference to it. Thus my questions aren't pointed at a possible issue here as the text that you can extract from a container file will be the file name when it is an embedded file.

                       But you may want to research the store a reference option as it may represent a simpler way to handle files that your users need to periodically open, modify and then save. As that can avoid most the extra scripting that you are doing here.

                       This part of your script puzzles me:

                         
                  •           Insert File [Insert; display content; Never compress; Cards::currentphotoeditingbefore; "$$filepath"]
                  •      
                  •           Insert File [reference; display content; Never compress; Cards::currentphotoeditingafter; "$$filepath"]

                       That should insert identical copies of the same file into two different container fields. They won't be "before" and "after" copies of the file as this would seem to take place before the user has any chance to modify the file.

                        

                  • 6. Re: Problems setting up a script to edit a photo in a container filed.
                    HenryRobinson

                         First I want to thank you for taking the time to help me with this problem. I do feel though that I am running at the very edge of my abilities. So instead of trying to explain more about how I got as far as I have I made a replica of the process in an example database. see attachment

                         When replicating the same process I did run into one odd problem were the changed image would not show up at all. So I added one script called continue that dose the following:

                         Insert File [reference; display content; Never compress; Cards::currentphotoeditingafter; "$$filepath"]

                         go to layout "confirm photo edit"

                         This resolved the new problem but still gives me the same issue that started all this.

                         I hope that this will help clear up what I am trying to do, how I am trying to do it, and what is going wrong.

                         p.s. sure hope I can upload a FileMaker solution as an attachment.

                         Looks like that is a no so here is a link

                          

                    • 7. Re: Problems setting up a script to edit a photo in a container filed.
                      HenryRobinson
                           

                                This part of your script puzzles me:

                           
                                  
                      •                Insert File [Insert; display content; Never compress; Cards::currentphotoeditingbefore; "$$filepath"]
                      •           
                      •                Insert File [reference; display content; Never compress; Cards::currentphotoeditingafter; "$$filepath"]
                      •      
                           

                                That should insert identical copies of the same file into two different container fields. They won't be "before" and "after" copies of the file as this would seem to take place before the user has any chance to modify the file.

                           again I am at the edge of my abilities here but I will try and explain what I think is happening. At first it is just inserting an identical copy into both containers but because the Cards::currentphotoeditingafter is a reference it changes when the user makes changes to the opened image.

                      • 8. Re: Problems setting up a script to edit a photo in a container filed.
                        philmodjunk

                             First thing that I did was add a layout based on Container Storage so that I didn't have to deal with a portal based on a somewhat odd relationship.

                             I then found that an image file had been inserted with the "store a reference" option specified which is why it cannot be displayed in the container field on my system as the file path found within it is invalid on my computer:

                             imagewin:/C:/Users/Bill/AppData/Local/Temp/S11.2/Untitled.bmp

                             This is a typical file path to the temporary folder for when the current user account is "Bill".

                             I then inserted an image from my computer into a new record, being careful to leave "Store a reference" unselected. The image inserted correctly.

                             When I clicked the pencil icon, I got the confirm layout and it correctly displayed an embedded copy of the file that I had inserted. I then clicked continue and both the "before" and "after" images correctly displayed in their respective container fields. Checking more closely, I also confirmed that the Before image was embedded and the after image was by reference to the copy exported to the temporary folder.

                             I then clicked accept changes and an image still correctly displayed in the container field in the Photos portal.

                             But the file now inserted into the Container Storage::Container field has been inserted with the "Store a reference" option specified. Once I quit and restart FileMaker, this temporary folder is purged and I get a "not found" error showing in the container field.

                             I then opened the script that is performed when you click the accept button and found that the script uses Set field to copy the (by reference) image from the "after" container field into the Container Storage::Container field and that is where the problem lies. You need, instead, to use insert picture to insert the image file from the temporary folder (use your $path variable), with the "store a reference" option unselected.

                             This requires that you add the Container Storage::Container field to your layout (you can hide it by making it very small with no borders and a transparent fill color.) You'll need to use go to field to put the focus in the field and then use insert picture to insert the modified copy into the container field.

                        • 9. Re: Problems setting up a script to edit a photo in a container filed.
                          HenryRobinson

                               I made one small change based on the information you gave me that fixed the problem.

                               On the script that accepts the changes I replaced

                               Set filed [Container storage::container; cards::CurrentPhotoEditingAfter]

                               with

                               Insert file [insert; Display content; never compress; Container storage::container; "$filepath"]

                                

                               Thank you so much for all your help on this problem.

                               I am wondering though, I can not be the only person out there that would like this function. Have you seen any other attempts at this and if so any of them that are done better then mine?

                          • 10. Re: Problems setting up a script to edit a photo in a container filed.
                            philmodjunk

                                 If one used strictly "store a reference" images in the container fields, this method is not needed. Only for embedded files or those in externally stored container fields is such a method needed.

                                 As a whole, your method seems well thought out. I've outlined a simpler method, but it doesn't do a before and after comparison, it just puts a "save" button where users can click to re-insert the modified file if they want to keep the changes.

                                 I think what you have in mind here would make a good feature request: http://www.filemaker.com/company/contact/feature_request.html

                            • 11. Re: Problems setting up a script to edit a photo in a container filed.
                              MichaelHart

                                   PhilModJunk - "I've outlined a simpler method, but it doesn't do a before and after comparison, it just puts a "save" button where users can click to re-insert the modified file if they want to keep the changes."

                              Where is the outlined "simpler method" you're referring to? It sounds like what I'm looking for.

                              Thanks.

                              • 12. Re: Problems setting up a script to edit a photo in a container filed.
                                philmodjunk

                                     It was in a different thread.

                                     Here's a general idea of how to do this:

                                     Script A.

                                     Step 1, compute a file path for the exported file and set a $$Path variable to that path. A file path is a list starting with a drive letter or volume name and including a list of all enclosing folders ending with the name of the file to be created. Since this is not a copy of the file we need to retain long term, we can use Get ( TemporaryPat ) to compute a file path to the temporary folder and concatenate a name for the file. FileNames can be extracted from the data in the container field. Make this a global variable (two dollar signs) so that this variable will continue to hold a value after the script has run.

                                     Step 2. Use the $$Path variable with Export Field Contents to export and open the file. The file will be opened by the "default application" specified for your Operating System for files of the same type as your exported file.

                                     Script B.

                                     Put a "save" button on your layout to perform a one line script. This script uses Insert File and the filepath/filename in $$Path to insert the modified copy of this file back into the container field. Note that script steps that start with "insert" will not work unless the specified field is present on the current layout and are Browse mode accessible.

                                     For a thread and downloadable file on $Path variables, extracting file names from container fields, container fields and the script steps that can use $path variables, see: Exploring the use of a $Path Variable in Scripts