7 Replies Latest reply on Nov 18, 2009 8:36 PM by jla_1

    Variable path export field revisted

    jla_1

      Title

      Variable path export field revisted

      Post

      I for the life of me cannot figure why the following doesn't work.

       

       

      • Set Field [ IMAGES::_gSelectedFolder; TrFile_SelectFolderDialog( "-Unused"; "Please select a folder:";) ]
      • Set Variable [ $path; Value:IMAGES::_gSelectedFolder ]
      • Go to Record/Request/Page[ First ]
      • Loop
      • Set Variable [ $file; Value:"filewin:/" & $path & GetAsText ( IMAGES::IMAGE1) ]
      • Export Field Contents [ IMAGES::IMAGEDISPLAYX; “$file” ]
      • Go to Record/Request/Page[ Next; Exit after last ]
      • End Loop
       
      The Specify File Output option is just "$file".  The previous incarnation of this works just fine:
       
    • Go to Record/Request/Page[ First ]
    • Loop
    • Set Variable [ $file; Value:GetAsText ( IMAGES::IMAGE1) ]
    • Export Field Contents [ IMAGES::IMAGEDISPLAYX; “filewin:/C:/ExportFolder/$file” ]
    • Go to Record/Request/Page[ Next; Exit after last ]
    • End Loop
    •  
       
      I need to have that option to designate an output folder.  After selecting a folder and using the export button which has the script attached, FM returns an error: "C:\**\**\**.jpg" cannot be created on this disk." 
        • 1. Re: Variable path export field revisted
          jla_1
             Hate to bump a thread, but anyone have any suggestions?
          • 2. Re: Variable path export field revisted
            philmodjunk
              

            Try using a calculation field or show custom dialog to expose the text being returned by GetAsText ( IMAGES::IMAGE1)

             

            I recently discovered that if you drag and drop an image or use insert object instead of insert file or insert picture, you don't get the file name you expect here.

            • 3. Re: Variable path export field revisted
              jla_1
                 Well, the GetAsText has been working.  If I hardcode the path in the Export Field Contents it works fine.  I have the field _gSelectedFolder displayed on the form after the user selects a folder and it shows the complete path, eg: C:\**\folderchosen.  I just can't for the life of me figure out why it's broken.  Could it a formatting issue withe filewin or the way FM sees a path?  I'm at my wits end as I need this option.
              • 4. Re: Variable path export field revisted
                philmodjunk
                  

                Taking a closer look at your script, shouldn't there be another slash in the path calculation that separates the last folder in $Path from the filename generated by the GetAsText function?

                 

                Set Variable [ $file; Value:"filewin:/" & $path & "/" & GetAsText ( IMAGES::IMAGE1) ]

                 

                That's consistent with the error message you report. I get that error message if I've munged up the file path somwheres.

                • 5. Re: Variable path export field revisted
                  jla_1
                    

                    You rock.  I spent all night and two FM Bible's trying to figure that out.  Works perfect.  

                   

                  Can I throw one more at you?  I also configured the same export to take the student id from a record and export the image with that name, eg: A student has id 100100, that image is exported as 100100.jpg instead of it's original name, DCM100.jpg.  The problem I'm having of course is that some student's have more than one image, so it exports the first image, renames it, then promptly overwrites it with the second image.  I had thought of an IF/Else statement in the loop using the mooplug Fileexists to somehow check to see if there are two images or if one already exists, then add a _1 or _b to the end of the image somehow, like 100100.jpg, 100100_1.jpg.  Any advice?

                   

                  ps. I basically just changed the code within the loop to: GetAsText ( IMAGES::ID) & ".jpg"  

                  • 6. Re: Variable path export field revisted
                    philmodjunk
                      

                    The student images are stored in separate records in a container field?

                    I'd define an auto-entered serial number in that field table and include it in the file name. You might put together something like this:

                     

                    100100_14563.jpg Where 100100 is the student ID number and the second value is the unique ID number of the specific image record. This requires zero looping and provides identifier numbers that won't change  even if you add or delete image records

                     

                    Images::ID & "_" & Images::ImageID & ".Jpg" would do the trick for you. (No need for GetAsText in this expression.)

                    • 7. Re: Variable path export field revisted
                      jla_1
                         Thanks, that works.