Reoder topgraph traces numerically or alphabetically

Is there a simple way to reorder traces in a graph alphanumerically?

OK, I'm stumped. I though that this was an easy request. This is what I cobbled together. It is getting hung up on the the reorderTraces line with an error that trace is not on graph which I take to mean that the string variable is not being taken properly. When I add some print statements the string list is as expected and if I run from the command line the sorted list that has been copied and pasted it produces the desired outcome.

Function ReorderTracesAN()

    // Get a list of traces
    String visibleTraces=TraceNameList("",",",1+4)  // only visible normal traces

    //Sort that list to be alphanumeric
    visibleTraces = SortList(visibleTraces,",",16) // 16:   Case-insensitive alphanumeric sort that sorts wave0 and wave9 before wave10

    //Before we do the reorder command we need to remove the last comma (list seperator) from the string list
    visibleTraces = removeending(visibleTraces)

    // reorder the traces assuming Igor Pro 7 using the _front_ keyword
    ReorderTraces _front_, {$visibleTraces}// this gives an error here
End


Andy
Wouldn't it be nice if that worked? But you can't turn a *list* into names with $, only single names. So this is one of those places where you probably really still need to use Execute, like this:
Function ReorderTracesAN(gname)
    String gname
   
    if (strlen(gname) == 0)
        gname = WinName(0,1)
    endif
 
    // Get a list of traces
    String visibleTraces=TraceNameList(gname,",",1+4)   // only visible normal traces
 
    //Sort that list to be alphanumeric
    visibleTraces = SortList(visibleTraces,",",16) // 16:   Case-insensitive alphanumeric sort that sorts wave0 and wave9 before wave10
 
    //Before we do the reorder command we need to remove the last comma (list seperator) from the string list
    visibleTraces = removeending(visibleTraces)
 
    // reorder the traces assuming Igor Pro 7 using the _front_ keyword
    String cmd = "ReorderTraces/W=" + gname + " _front_, {" + visibleTraces + "}"
    Execute/Q cmd
End

Note that I have also added an input, gname, to make the whole thing a bit more robust.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com