cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
Neo
Neo
Level VI

How to create a user prompt to import multiple data files from a user selected path and user selected "Set Name Filter"?

I would like to create a user prompt dialog box using the Multiple File Import() function, which asks the user for 

File Name Filter

(which goes to Set Name Filter. Default filter in the user input field could be Test_ABC* (note with wild card))

 

Path to Files

(default could be My Documents, but user needs to be able to browse to where the actual files are. This path goes to the folder field in Multiple File Import)

 

Only two files are to be selected in my case. So in the Multiple File Import window only two files Set Name Filter are expected to be active, rest greyed out.

Clicking OK button on the user prompt dialog box, both files should be imported with the functionality of passing the smaller sized file to data_file1 and the larger sized file to data_file2. data_file1 and data_file2 are to be referenced in my script after this user input prompt. 

Clicking Cancel button should abort the stop any further execution. 

How to do this in JSL?

 

When it's too good to be true, it's neither
4 REPLIES 4
StarfruitBob
Level VI

Re: How to create a user prompt to import multiple data files from a user selected path and user selected "Set Name Filter"?

Hello @Neo,

 

This should get you started.  No Multiple File Import window will pop-up, it's built into the functionality of the new window.  It's not pretty, but it works.  Notice the items that happen only after the user presses the "OK" button. Hope this helps!

 

Names default to here(1);

// Creates window and asks user to a name to user for filtering
name_filter_win = New window( "Name filter",
	
	vbox = v splitter box( // Contains 3 elements
		
		// Element 1: Title
		text box( "Enter file name filter" ),
		
		// Element 2: Text input box
		name_filter = Text edit box( "" ),
		
		// Element 3: Button & script that runs after it's pressed
		Button Box( "OK",
			mfi_name_filter = name_filter << Get text(); // Gets text from text box
			
			pick_dir = Pick directory( "Select a folder" ); // User chooses destination folder
			
			Eval( // Multiple file import code
				eval expr(
					Multiple File Import(
					<<Set Folder( expr( pick_dir ) ),
					<<Set Show Hidden( 0 ), // 0 = does not include hidden stuff, 1 = include hidden stuff
					<<Set Subfolders( 0 ), // 0 = not recursive, 1 = recursive
					<<Set Name Filter( expr( mfi_name_filter ) ),
					<<Set Name Enable( 1 ),
					<<Set Add File Name Column( 0 ),
					<<Set Add File Size Column( 0 ),
					<<Set Add File Date Column( 0 ),
					<<Set Import Mode( "CSVData" ),
					<<Set Charset( "Best Guess" ),
					<<Set Stack Mode( "Stack Similar" ),
					<<Set CSV Has Headers( 1 ),
					<<Set CSV Allow Numeric( 1 ),
					<<Set CSV First Header Line( 1 ),
					<<Set CSV Number Of Header Lines( 1 ),
					<<Set CSV First Data Line( 2 ),
					<<Set CSV EOF Comma( 1 ),
					<<Set CSV EOF Tab( 0 ),
					<<Set CSV EOF Space( 0 ),
					<<Set CSV EOF Spaces( 0 ),
					<<Set CSV EOF Other( "" ),
					<<Set CSV EOL CRLF( 1 ),
					<<Set CSV EOL CR( 1 ),
					<<Set CSV EOL LF( 1 ),
					<<Set CSV EOL Semicolon( 0 ),
					<<Set CSV EOL Other( "" ),
					<<Set CSV Quote( "\!"" ),
					<<Set CSV Escape( "" ),
					<<Set XML Method( "guess" ),
					<<Set XML Guess( "huge" ),
					<<Set XML Settings( XML Settings() ),
					<<Set JSON Method( "guess" ),
					<<Set JSON Guess( "huge" ),
					<<Set JSON Settings( JSON Settings() ),
					<<Set PDF Method( "guess" ),
					<<Set PDF Settings( PDF All Tables( Combine( All ) ) ),
					<<Set Import Callback( Empty() )
					) << Import Data	
				) 
			);
			
			name_filter_win << Close window; ) // closes window		
	)	
);
Learning every day!
Neo
Neo
Level VI

Re: How to create a user prompt to import multiple data files from a user selected path and user selected "Set Name Filter"?

@StarfruitBob . Thanks. I made some changes under Multiple File Import block and the script now has the basic functionality needed. There are few improvements I would like to make.

  1. Make the "Name Filter" window modal. Update: This I have done now.
  2. Pre join additional text and post join an asterix (wild card)  to construct mfi_name_filter. Update: This I have done now.
  3. Have only JMP files visible inside the window when user chooses the files. This functionality is important. Struggling to do.
  4. Count the number of JMP files in the selected folder and report if more than two. Warn the user of more that two files and stop further execution if more than two JMP files are present. Not there yet.

 

Any help is appreciated. I will try my hand for items 1 and 2 but am unsure how to implement 3 and 4. For item 3, Do I need to use Pick File for this in place of Pick Directory?

 

 

 

When it's too good to be true, it's neither
StarfruitBob
Level VI

Re: How to create a user prompt to import multiple data files from a user selected path and user selected "Set Name Filter"?

3. In the name filter, you should be able to add  *.jmp, which is only jmp data tables.

4. You'll still need pick directory, but you will need to add in Pick file.
    4a. Pick file will return a list of all files in the directory specified, this includes both *.jmp files and ones that are not.
    4b. You will need to remove from( list of files from Pick file, anything that has last 3 character that are not jmp )

          This will leave you with a list of the files, specified by Pick Directory, only ending in jmp.

 

After 4, you can do N Items( Pick file list ) = # of *.jmp files in the directory.  Does this make sense?

If anyone has an easier way of doing this, please let us know!

Learning every day!
txnelson
Super User

Re: How to create a user prompt to import multiple data files from a user selected path and user selected "Set Name Filter"?

I suggest you take the time to read the section on Multiple File Import in the Scripting Guide,  in the JMP Documentation, accessed through the Help pull down menu.  It has an example of finding specific files, and then opening MFI with only the found files displayed.

txnelson_0-1684960337783.png

 

Jim