getwindow wavelist order

I am trying to get information about waves plotted on a graph.
I am currently using:
getwindow/Z $temp_str , wavelist
where temp_str is the name of the plot of interest
Initially I hoped this would be exactly what I want, W_wavelist contains almost all the info I need.
The order of the waves however seems to the order the waves were added to the experiment, rather than the order of the waves displayed on the graph.
Is there a way to get a list of the waves displayed on the graph, in the order they were displayed?

Ideally I am looking for a way to programmatically generate the table that is achieved by right clicking in a graph and selecting the "Remove from Graph" option.
As I am putting waves of the same name, but originating from different folders, I really want the full path to the wave.

On a related note, I have tried some workarounds using:
AppendtoGraph\TN = tracename
the result is that I get an "unknown flag" error, even though I am using Igor 6.37

Also I have tried using:
TraceNameToWaveRef("","wave0#1")
and I get an error stating "ambiguous wave point number", even though I have verified that this wave is in fact on the graph

Any other suggestions?

The list of trace names returned by TraceNameList() is in the order in which the traces were added (or in the re-ordered order if you use ReorderTraces). Here is a function that will give you a list of the waves corresponding to the traces in a graph:
Function/S ListGraphWaves(graphname)
    String graphname
   
    if (strlen(graphname) == 0)
        graphname = WinName(0,1)        // top graph
    endif
   
    String traces = TraceNameList(graphname, ";", 1)
    Variable ntraces = ItemsInList(traces)
    Variable i
    String theList=""
   
    for (i = 0; i < ntraces; i += 1)
        Wave w = TraceNameToWaveRef(graphname, StringFromList(i, traces))
        theList += GetWavesDataFolder(w, 2)
    endfor
   
    return theList
end

Quote:

On a related note, I have tried some workarounds using:
AppendtoGraph\TN = tracename
the result is that I get an "unknown flag" error, even though I am using Igor 6.37

The /TN flag goes after the Y wave:
AppendToGraph ywave/TN=MyCoolTraceName
Quote:

Also I have tried using:
TraceNameToWaveRef("","wave0#1")
and I get an error stating "ambiguous wave point number", even though I have verified that this wave is in fact on the graph

I don't think you're showing us enough to figure out what went wrong. It needs to be used someplace where a wave reference is expected, as in the WAVE statement above.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
I spent way to long reading the Igor help documentation for this and it still was just not very clear.
Thanks for the prompt response, this example code you provided is a great help.