Other than editing a sketch or #include file, what is the best and convenient method to set a #define macroname in a specific sketch during compile time ? I'd like to do this when I Verify or Upload or Export Compiled Binary from within the IDE.
Using a reguar C or CPP command line compiler invocation, I'd use the compile option -Dmacroname
Every board family in the Arduino IDE has its own support package with two main config files : `board.txt' (config options for each board) and 'platform.txt' (common build options for whole board family).
You can't. That flag is for when you are using Arduino CLI to compile your sketch from the command line.
But if you add -D flags to the compilation patterns defined in the platform configuration files mentioned by b077, that change applies to Arduino IDE and Arduino CLI both.
That's good to know, thanks. However, I was hoping there was a dialogue/UI in the IDE to allow me to do it for a particular sketch, but I can understand its not a priority feature given I can just edit the .h file in the IDE.
Although it is less common to see this, in addition to the primary .ino file, Arduino sketches can contain .h files. You can add them by clicking the ▼ icon on the right side of the editor toolbar, selecting "New Tab" from the menu, and then using the .h file extension when naming the tab. The IDE editor will show any .h files in the sketch as tabs and you can edit their contents. You might use such a file to hold declarations of objects defined in .cpp, .c, or .S files in the sketch, similar to the header files of a library, only not installed as a library.
Editing the sketch code is an effective way of changing macro definitions assuming the affected code is in the sketch. If the affected code is in the source file of a library, core, or toolchain component then the ability to edit the sketch code doesn't help us. That is one of the use case for setting global macros via the -D compiler flag.