December 5, 201312 yr Hi folks. I am trying to create a script in FM11 Advanced. The script needs to import a folder of images into the solution I am creating. The trouble I am having is I need the user to be able to choose the folder, but I don't want them to have control over any other part of the import. It doesn't seem possible to do this using the Import Records script step. Hoping someone knows a workaround for this issue as I am stuck! Thanks in advance for any help anyone can offer
December 5, 201312 yr Author I figured it out. Still wondering if there is an easier way to do this though, out of interest. For anyone else trying to do the same thing here' what I did: I created a container field and set it to 1PX by 1 PX as it does have to be on the layout in question to work. I then went about getting the Import Folder path as a variable from the user. I used the Insert File script step making sure to check the Store only a reference box, and set Go to target field to the container I had just created. I also used a custom dialog here to tell the user to choose the first image in the folder to be imported (in reality it doesn't matter which image is chosen, you are simply getting a reference to the folder you need) I then set the variable to work on either a PC or a Mac (in my case I used a global variable as the actual import is in a different script): If [Get (SystemPlatform) = -2] Set Variable [$$ImportPath; GetAsText ( Replace ( GetAsText ( Left ( GetAsText ( Container_Field_Name) ; Position( GetAsText ( Container_Field_Name ) ; "/" ; Length ( GetAsText ( Container_Field_Name ) ); -1) ) ) ; 1 ; Position ( Container_Field_Name ; "filewin" ; 1 ; 1 ) - 1 ; "" )) Else Set Variable [$$ImportPath; GetAsText ( Replace ( GetAsText ( Left ( GetAsText ( Container_Field_Name) ; Position( GetAsText ( Container_Field_Name ) ; "/" ; Length ( GetAsText ( Container_Field_Name ) ); -1) ) ) ; 1 ; Position ( Container_Field_Name ; "filemac" ; 1 ; 1 ) - 1 ; "" )) Finally I used the Set Field script step to empty the container field. I could then specify the data source in the import script step and set the folder location to $$ImportPath, specify the import order and check perform without dialog. End result is when the user clicks the import button that I placed on the layout, they get to choose the which folder their images are in and everything else is automated. Again if anyone has a simpler solution, I'd love to hear it!
June 17, 201411 yr Nice little example of scripting a folder import. On a side comment: to get the parent folder path of the item, it might be helpful to use a custom function like this: // FileParentFolderPath ( somePath; pathDelim ) // version 1.2, Daniel A. Shockley // Returns the path to the parent folder of the given path, using the specified directory delimiter. /* VERSION HISTORY 1.2 - if no path delimiter is specified, use a normal forward slash. 1.1 - rewrote to take advantage of much simpler method */ Let ( [ pathDelim = If ( IsEmpty ( pathDelim ); "/"; pathDelim ) ]; Left ( somePath; Position ( somePath; pathDelim; Length ( somePath ) - 1; - 1 ) ) ) Note that takes two parameters, the file path and the path delimiter (although if you leave the delimiter empty, it assumes you are using forward slash). You'd still need to add "filewin:" or "filemac:" for your code above, but this is an example of when a CF can make code much easier to read and debug or change.
June 17, 201411 yr If you are not opposed to using plugins, I think the BaseElements plugin by goya would work nicely for you. It has a function that lets you select a folder. http://www.goya.com.au/baseelements/plugin It is free!
Create an account or sign in to comment