How to Call a Function or Macro from Another Igor File?

I have code I use in a lot of instances (like, hundreds of different files), meaning that if I ever write an update to it, things are very painful.  Can I - and how to I - make it so that I can store all my functions/macros in one file and then just refer to that file to run them?

If you store your code in .ipf files in your User Procedures folder, you can load in an .ipf file to a new experiment and use the code. When you update that .ipf file it will be updated in every Igor experiment in which it is loaded. All your functions and macros don't have to be in one file. They can be in separate files and you can load different files using the include statement.

In reply to by ChrLie

I recommend using "Igor Procedures" for procedure files that you intend to use very often. As ChrLie says, for details, execute:

DisplayHelpTopic "Special Folders"

Also

DisplayHelpTopic "Types of Procedure Files"

 

Okay, I feel like I'm missing something.  I made a new procedure window in an experiment, pasted my code in, and then Save Procedure As ... to my Igor Procedures folder in my user directory.  Quit Igor, re-open for a new experiment.  Based on the help topics, it seems like it should automatically load all of the functions in that procedure (.ipf) file.  But it doesn't.  If I open that procedure file in Igor, it can run it fine, but if I close it, it won't recognize any of the functions.

Am I misunderstanding the behavior, or am I doing something incorrectly?

I may've just answered my own question ... if I put the procedure file into my Applications/Igor Pro 7 Folder/Igor Procedures, then I can get it to work.  However, I had a macro in there and it claimed the macro already existed, so it seems like it still scanned the one in my user directory, but it still wouldn't let me run anything.  Is that expected?

In reply to by astrostu

>if I put the procedure file into my Applications/Igor Pro 7 Folder/Igor Procedures

Don't use that folder. Use the Igor Procedures folder in your "Igor Pro User Files" folder. For details, execute:

DisplayHelpTopic "Special Folders"

To find your "Igor Pro User Files" folder, in Igor click Help->Igor Pro User Files.

After saving the procedure file in the "Igor Procedures" folder in your "Igor Pro User Files" folder, verify that it is in the right folder. Then restart Igor. Then click Windows->Procedure Windows. You should see the name of your procedure file there.

Yeah, I see it there, but unless I actually open that procedure window, I can't use the procedures in it.  Whereas if I have it in the /Applications/.../Igor Procedures, then I can use them without needing to open that procedure window.

...

Ohhh...... okay, I think I figured it out.  If I do open that procedure window, which I seem to only have done when test-put it in the ~/Documents/.../Igor Procedures, and then close it and press Kill, then it won't work.  If I open anew, see it there in Windows/Procedure Windows >, then DON'T open it, it still runs fine.

Okay, problem solved.

As an additional note (actually two):

- you do not actually put the .ipf procedure itself into the Igor Procedures folder. A windows shortcut to the real .ipf file somewhere else will do just fine. This way you can have your written procedures in a dedicated folder somewhere within your documents. Makes it less likely to forget backupping, copying or recovering your precious procedures.

- If you have saved the procedure file from your main procedure window within Igor Pro (the one you get when you press 'Ctrl+M') than chances are high that the new procedure file will cause '... already exists' errors, since the function macro now exists both in the main procedure window of the current experiment AND the additionally loaded procedure file. The solution is to either rename any macro or function to a different name before saving it to a file or to delete the function/macro in the main procedure window of old Igor experiment files (since you do not need it there anyway when you have the extra file loading every time). Or you just never use the main procedure window when you intend to save the file later anyways: Use 'Window' => 'New' => 'Procedure ...' instead.