Repeated text file imports


#1

Are there any tricks that can speed up or sidestep use of the text import wizard when I have 8-10 identically formatted text files to import? Each one is an order, so they have to be done one at a time. I tried recording an import which yields this, for example:

importtext lftocr(binarytotext(fileload("/Users/bkahn/Downloads/BF#5614 794174"))),“ExistingData”,“Replace”,“AddFields”,“No”,“ReArrange”,importcell(1-1)+tab()+importcell(2-1)+tab()+importcell(3-1)+tab()+importcell(4-1)+tab()+importcell(5-1)+tab()+""+tab()+importcell(6-1)+tab()+importcell(7-1)+tab()+importcell(9-1)+tab()+importcell(10-1)+tab()+importcell(11-1)+tab()+importcell(12-1)+tab()+importcell(13-1)+tab()+importcell(14-1)+tab()+importcell(15-1)+tab()+importcell(16-1)+tab()+importcell(17-1)+tab()+importcell(18-1)+tab()+importcell(19-1)+tab()+importcell(20-1)+tab()+importcell(21-1)+tab()+importcell(22-1)+tab()+importcell(23-1)

where this is the text file name being imported: BF#5614 794174

The wizard works fine but there’s a lot of clicking to do for each import and if there’s a way to streamline it, I’d be delighted.

Thanks,
bk


#2

Two ways:

  1. Once you have configured the text import wizard, save the configuration as a template. Then you can reuse this template for the next files.
  2. You have recorded your import procedure already. So you do not need the wizard any more, just your procedure.

#3

I’ve saved the template already, but in my imagination I’d only have to drag in the text file and the remaining steps would happen without any clicking. As it is now, I still have to tell the import to replace the existing data. And I get an error message if I leave the import wizard window open while doing other stuff. If I close it, then I have to reselect the template each time.

And the procedure only contains the path to the file I used when recording. That needs to change for each new import.

This is all niggling stuff, I know, but I feel like if I just knew more, I could code this so it would be truly a drag and drop and everything would be done without extra clicks or random error messages.

thanks
bk


#4

Re: [Panorama Discussion Forum] [Panorama X] Repeated text file imports
The text file being imported in your procedure is the one you chose when recording the procedure. You would likely want to replace the “/Users/bkahn/Downloads/BF#5614 794174” with a variable and fill that variable with the desired file name prior to running the importtext function.


#5

I tried that too. (Maybe at age 70 I am striving for a new level of laziness?) And it works, but copying and pasting the new file name–sitting in the downloads folder-- so that the variable can do it’s thing is also not very elegant.

Is there a way to do this with the drag receiver object in a form? I didn’t see any examples of how to use it in the tutorial but if I could drag each text file into there and have the rest happen ‘automatically’ that seems like a slick solution.

thanks
b


#6

I have done something like this with drag receiver. Here are the bare bones of a procedure:

/*This procedure will use a drag receiver to build an array of file path names, 
with a cr() separator, for files dropped on the drag receiver.
Then you can use loop array to process those files. */

fileglobal lvtext,lvnewfile,lvcounter,lvtextfiles
lvtextfiles=info("dropfiles")
lvnewfile=""

looparray lvtextfiles, cr(), lvtext, lvcounter

/* The first time through the loop, the procedure will use the first file name, 
load that file into a variable. Then you can use an import procedure to 
process that variable. Then it will move to the next file, and so on, to 
the end of the list of files dropped.*/

lvnewfile=fileload(lvtext)

//[Your procedure for importing one file]

endloop

I am not sure if you would have to do something different for a binary file, but it looks like this structure would still work.


#7

You could replace that path in your procedure with a simple Open File dialog. See the Pan X Help for openfiledialog.


#8

An excellent suggestion. Now I have this:

local fileChoice
choosefileDialog fileChoice

importtext lftocr(binarytotext(fileload(fileChoice))), etc. etc.

Pan X Help suggested the newer choosefileDialog to replace openfiledialog. Anything I find easy to use is really truly easy.

I’ll try the drag receiver method when I have more time as I find that intriguing. For now I am a happy camper.

Thanks to all,
bk


#9

Rather than having to create a drag receiver you can simply use a gettext to drag the file to from the Finder. The only gotcha is that you first have to click into the gettext edit box to make it active before you do the drag.

local theFilePath
gettext "Drag filke from Finder…", theFilePath

This puts the file path into the variable theFilePath ready to use in your import procedure.


#10

Sweet! I had no idea this was possible.

thanks

bk


#11

That is cool, but you can also drag files from the finder into the standard open file dialog. So if you started your procedure with this code:

local fileChoice
choosefiledialog fileChoice
importtext lftocr(binarytotext(fileload(fileChoice))), etc. etc.

you could either select the file using the dialog, or simply drag the file from the Finder to the dialog – best of both worlds :slight_smile:


#12

Too bad the normal Text Editing Object does not also support this drag receiver characteristic. I have to assume it is a different animal than the text input box used with gettext and the choosefiledialog.


#13

If the Text Editing object is already active (flashing insertion point) then you can drag text or files into it. But if it is not active yet, it doesn’t work (I agree that could be nice, and it would also be nice if Image Display objects could be used as drag receivers).


#14

Not in my experimenting. With the TEO active (the focus ring highlighted and insert cursor flashing), draged text or a file does not get entered when dragged into the object.


#15

I can’t explain your results – I did the same experiment before I posted and it worked. Ok, I tried it again, it still works, here is a movie.

In any case, this is not Panorama code doing this, but standard macOS behavior. So maybe you are on a different version of macOS and it is somehow working differently.

In my case the Text Editor object was linked to a database field – what was yours linked to?


#16

It was linked to a variable but I just changed it to be linked to a field and it still does not work. Here is the Properties panel for the TEO:


Strange that the drag does work for the gettext edit box but not in a TEO.

I’m running High Sierra Version 10.13.4.


#17

Ok, I just found the problem. I was simply dragging the text into the middle of the TEO instead of into the line that had the blinking cursor. Once I saw my error I noticed that the dragged text would show a + cursor when I was over the line in the TEO with the blinking cursor.


#18

It looks like Jim is also dragging into the middle of the TEO, but he is dragging from above, so it crosses the line with the blinking cursor.


#19

By the way, in addition to dragging files into Text Editor objects, you can also drag a file into procedure code and the path will be copied into the code. I’m sure some of you already know this, but perhaps this will be a helpful tip for some. I just thought of this because I was doing some programming and needed the path of a file – so I just dragged it into the code from the Finder!