"Drag and drop" running of a procedure file
supra
How can I run that procedure file by simply drag and dropping my import txt file directly into a new Igor table/experiment and without opening a file browser.
I saw if I drag a txt file into new igor table/experiment by default it open "delimited text import option" . I wonder whether I can change that to my procedure file ...so that if I drag a text file it will run my procedure file and load my import file.
The trick is you will need to be able to identify from the parameters to the hook function whether this is an event that you want to handle, in which case you return 1 from the function, or if it is an event you want Igor to handle, in which case you return 0 from the function.
January 19, 2012 at 12:59 pm - Permalink
Does this "BeforeFileOpenHook" function need to be inserted in my procedure file ?
the problem is my import data file has simple .txt extension that
igor recognize and has a hook for it attatched to "delimited text import" option. How can I tell igor to it change that to my procedure.....which Igor procedure file does has this hook (BeforeFileOpenHook) for txt file ? I tried to look inside the igor procedure but didint find...I saw people write BeforeFileOpenHook procedure for importing excel file using xop. But don’t know how I can write or use a already Igor BeforeFileOpenHook for txt file to attach my procedure. Do I need to use xop ?
I also tried to make a another ipf file (myfiletype.ipf) with the following code and placed in igor procedure folder but that also didnt work..still igor understand that it is delimited file and by default open demited taxt import option. ( sorry for my poor prog skill..I am new in Igor). Do I need to put that kind of code inside my procedure ?
myfiletype.ipf
---------------------
#pragma rtGlobals=1 // Use modern global access method.
Function BeforeFileOpenHook(refNum,fileName,path,type,creator,kind)
Variable refNum,kind
String fileName,path,type,creator
Variable handledOpen=0
if( CmpStr(type,"txt")==0 ) // text files only
handledOpen= 1 // returns 1 if loaded OK
endif
return handledOpen // 1 tells Igor not to open the file
End
I attached my procedure file and a simple text import data file.
I would really appreciate if you can give me some more clue..
January 19, 2012 at 03:15 pm - Permalink
It needs to be in some open procedure window. If you want this to be available all of the time, you would need to create a "global" procedure file. For details, execute:
In your case though, you may as well put it in the same file as the function you will be calling (apparently LoadAndGraphXYa).
If you want your function to handle all .txt files then you are set. Otherwise your hook function would need to use some distinctive characteristic of the file to decide if it is to be handled by your hook function or by Igor. The sample file you attached is not very distinctive - the best you could do would be to examine the contents of the file, detect if it consists of two columns, and handle it based on that. However, your detection scheme might get it wrong for some files.
It would be easier and better if your file had a distinctive extension or something distinctive in the file name that you could look for.
Your code is expecting the type parameter to contain the file name extension. However, it contains a "file type code" such as "TEXT" for plain text files. It would work if you changed the CmpStr line to compare with "TEXT", as in the example under BeforeFileOpenHook.
To learn about file type codes, execute:
However, since the demise of Mac OS 9, file type codes are antiquated and you are better off using the file name extension, like this:
if (CmpStr(extension,"txt") == 0)
Print "This is a .txt file" // For debugging only
else
Print "This is not a .txt file" // For debugging only
endif
January 19, 2012 at 08:25 pm - Permalink
1. I usually put myfile.ipf and import.ipf in global procedure folder ( Igor procedure folder). This time I put both the code in a single file ( testimport.ipf )
2. Since I am ok to run my import code ipf file for all type of .txt file, so I changed type "txt" to "TEXT" or used your suggested file type detection code ...but now if I drag the input text file in the Igor table it does nothing ( it doesnot also invoke the default Igor "delimited text import" option
3. Am I missing something ? do I need to tell Igor to run LoadAndGraphXY after the file is dragged and dropeed to Igor and then the BeforeFileOpenHook get fired?
4. Usually I use a file browser to supply the filename and pathname to the function LoadAndGraphXY(""."") . In case I need to tell to run LoadAndGraphXY after I drag and drop the file to Igor ,then how I supply the filename , path name to the function ? ( Is it from BeforeFileOpenHook it gets the "fileName" and "pathName"
testimport.ipf
-------------------------
#pragma rtGlobals=1 // Use modern global access method.
Menu "Single"
"Load Single file...", LoadAndGraphXY("", "")
End
//---------------------------------------
Function BeforeFileOpenHook(refNum,fileName,path,type,creator,kind)
Variable refNum,kind
String fileName,path,type,creator
Variable handledOpen=0
if( CmpStr(type,"TEXT")==0 ) // text files only
handledOpen= 1 // returns 1 if loaded OK
endif
return handledOpen // 1 tells Igor not to open the file
End
//-----------------------------
Function LoadAndGraphXY(fileName, pathName)
String fileName // Name of file to load or "" to get dialog
String pathName // Name of path or "" to get dialog
// Load the waves and set the globals
LoadWave/G/A/E=1/D/O/P=$pathName fileName
.......
.......
return 0
End
January 19, 2012 at 09:33 pm - Permalink
Variable refNum,kind
String fileName, pathName,type,creator
Variable handledOpen=0
if( CmpStr(type,"TEXT")==0 ) // text files only
// *** Call Your Function Here ***
LoadAndGraphXY(fileName, pathName)
handledOpen= 1 // returns 1 if loaded OK
endif
return handledOpen // 1 tells Igor not to open the file
End
Your function had a parameter named path. I changed it to pathName to emphasis that the parameter contains the name of an Igor symbolic path (or possibly ""), not a file system path. To learn about or refresh your memory about Igor symbolic paths, execute this:
January 19, 2012 at 10:19 pm - Permalink
January 20, 2012 at 08:27 am - Permalink