Repeated text file imports

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.


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.

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.


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.

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.


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

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.*/


//[Your procedure for importing one file]


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.

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

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,

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.

1 Like

Sweet! I had no idea this was possible.



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:

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.

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

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.

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?

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.

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.

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.

1 Like

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!

I have jumped through the new hoops and mostly get things done in PanX now, almost as quickly as in the old 6 days. However, there is a bug(?) in the template saving routine. It will not accurately save a template that does not import the first field. Every field is shifted over to the left. After some hours of thrashing, I kludged by using the little formula box at lower right of the window to add a blank line (return) at the beginning, which shifts everything over one field to the right, and it now works. Shouldn’t have to do it this way, and if there is a “right” way to do it, I’d like to know.