Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

Import Folder via script where user chooses folder only


This topic is 3810 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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 :)

Posted

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!

 

  • 6 months later...
Posted

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. 

This topic is 3810 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.