7 Replies Latest reply on May 31, 2012 6:15 AM by philmodjunk

    Help with a container export script

    MarcMcCall

      Title

      Help with a container export script

      Post

      Hey guy,

       

      Here's another question for the FM experts on here..  I want to export a photo as a place holder for parts I have not photographed yet.  Here is my thought, unless someone has a better idea.  I want to set up a global container with the image that I will use for all of my place holder temporary photos.  What my plan would be is when I need to upload some parts to my website, I will be in a found set of records.  I will export the parts to an XLS file, then upload the photos.  I'm thinking of a script that takes the sku_item_code and adds it to the global containers file name which would be _400x400.jpg  My photo naming structure always follows that structure.  "HEP20146_400x400.jpg"  and so on.

       

      So my thought are if I name the photo in the container _400x400.jpg, I can sipmly add the sku_item_code to the front of the file name on export and the photo will be associated corectly on the website, till I have time to import the final one after it is photographed..  I would need a script to loop through a found count of records.

       

      Thanx in advance for any help and sugestions.

        • 1. Re: Help with a container export script
          philmodjunk

          Use Set Variable to put the file path and file name into a variable. Text calcualtions can combine data from fields in the current record with text in quotes to produce your file name.

          Then Use Export Field Contents with that variable to export the contents of the container field to a specified location and with the name your calculation created..

          • 2. Re: Help with a container export script
            MarcMcCall

            Thanx Phil,

             

            Thanx for getting me thinking.  I had a script already in place for something else, and was able to adapt it for this.  This is what I used in case any one else looks for posts on scripts.  This script actually makes a directory folder on the desktop and places the photos in it.

             

            • Allow User Abort [ Off ]
            • Set Error Capture [ On ]
            • Go to Record/Request/Page [ First ]
            • Loop
            • Set Variable [ $dirName; Value:"EVO PlaceHolders" ]
            • Set Variable [ $desktopUse; Value:Substitute ( "/" & Get ( DesktopPath ); [ "//" ; "" ]; [ "/" ; "\\" ]) ]
            • Send Event [ open document/application; "cmd.exe /C MKDIR " & Quote ( $desktopUse & $dirName & "\\" ) ]
            • Set Variable [ $filename; Value:GetAsText (T15_Products::sku_item_code & "_400x400.jpg") ]
            • Set Variable [ $output; Value:"file" & Case ( Abs ( Get ( SystemPlatform ) ) - 1 ; "win:" ; "mac:" ) & Get ( DesktopPath ) & $dirName & "/" & $filename ]
            • Export Field Contents [ T15_Products::GlobalContainer; “$output” ]
            • Go to Record/Request/Page [ Next; Exit after last ]
            • End Loop 
            • 3. Re: Help with a container export script
              philmodjunk

              I've been looking for a good example of how to execute a windows command line from a FileMaker script, So I've saved that example for future reference.

              Have you tried this line?

              Set Variable [ $output; Value:"file:" & Get ( DesktopPath ) & $dirName & "/" & $filename ]

              That should work on both platforms without having to modify the path used.

              You can also remove a GetAsText function call to get:

              Set Variable [ $filename; Value:T15_Products::sku_item_code & "_400x400.jpg" ]

              and it will work exactly the same.

              • 4. Re: Help with a container export script
                MarcMcCall

                I was thinking there was a more streamlined version, but it was working very well in the other script, I just left it alone.  I'm glad I finally posted something you may use for future reference... 

                • 5. Re: Help with a container export script
                  philmodjunk

                  And come to think of it, since you use a command line to create the directory, checking for Mac platforms won't accomplish much as that part of the script will not work on a Mac system anyway...

                  • 6. Re: Help with a container export script
                    MarcMcCall

                    Phil,

                     

                    There was a lot of the origional script missing in my earlier post (I took it out and did not use it), this should have what you are looking for if used on a MAC,  it has the perform AppleScript steps in it.  I removed a lot of steps for use in the script for this post, but see if there is something of better use for you here.

                     

                    • Allow User Abort [ Off ]
                    • Set Error Capture [ On ]
                    • #--------------------------------------Freezes the window and navigates to the Preferences Screen....
                    • Freeze Window
                    • #
                    • #--------------------------------------Sets the name of the folder to be created on the user's Desktop...
                    • Set Variable [ $dirName; Value:"Products_Backups" ]
                    • If [ Abs ( Get ( SystemPlatform ) ) - 1 //windows ]
                    • #--------------------------------------If the current operating system is a Windows machine...
                    • #--------------------------------------A folder will be created using the $dirName variable if the folder is not already created.
                    • Set Variable [ $desktopUse; Value:Substitute ( "/" & Get ( DesktopPath ); [ "//" ; "" ]; [ "/" ; "\\" ]) ]
                    • Send Event [ open document/application; "cmd.exe /C MKDIR " & Quote ( $desktopUse & $dirName & "\\" ) ]
                    • Else
                    • #--------------------------------------If the current operating system is not a Windows machine, meaning that if it is a Mac...
                    • #--------------------------------------A folder will be created using the $dirName variable if the folder is not already created.
                    • Perform AppleScript [ Native AppleScript: set theOutputFolderPath to path to desktop folder set theNewFolderName to "Products_Backups" tell application "Finder" if (exists folder (theOutputFolderPath & theNewFolderName as string)) = false then make new folder at desktop with properties {name:theNewFolderName} end if end tell ]
                    • End If
                    • #--------------------------------------The file name is set in variables based on the current Date and Time, and a copy of the Databse is saved to the appropriate folder on the user's Desktop.
                    • Set Variable [ $filename; Value:GetAsText ("Products" & "_" & GetAsText( Substitute ( Get (CurrentDate) ; "/" ; "_")) & "_" & Substitute ( Substitute ( GetAsText (Get(CurrentTime)) ; ":" ; "" ) ; " " ; "") & ".fp7") ]
                    • Set Variable [ $output; Value:"file" & Case ( Abs ( Get ( SystemPlatform ) ) - 1 ; "win:" ; "mac:" ) & Get ( DesktopPath ) & $dirName & "/" & $filename ]
                    • Save a Copy as [ “$output” ] [ copy of current file ]
                    • Set Variable [ $error; Value:Get ( LastError ) ]
                    • #
                    • Refresh Window [ Flush cached join results; Flush cached SQL data ]
                    • If [ $error ]
                    • #--------------------------------------If there was an error in the saving of the backup, an error dialog will display...
                    • If [ $error = 3 ]
                    • Show Custom Dialog [ Title: "Backup Error:"; Message: "There was an error making the Backup of your Database. You may only make a backup with a local copy of this database."; Buttons: “OK” ]
                    • Else
                    • Show Custom Dialog [ Title: "Backup Error:"; Message: "There was an error making the Backup of your Database. Database was not backed up. Error: " & $error; Buttons: “OK” ]
                    • End If
                    • Else
                    • #--------------------------------------If the Database saved successfully, a dialog will display alerting the user to the fact...
                    • Show Custom Dialog [ Title: "Backup"; Message: "Your Database has been backed up successfully."; Buttons: “OK” ]
                    • End If 
                    • 7. Re: Help with a container export script
                      philmodjunk

                      Thanks!

                      Why does your script have a Refresh WIndow [flush.... step in it? What happens if you remove that step? or Remove the "flush" parameters?