RemoveFromGraph Tracenamelist

What is amiss here.

I am creating a button to clear the active window of all the traces

Function RemoveAll(ctrlName) : ButtonControl
    String ctrlName

    String Alltraces
    alltraces = removeending(tracenamelist("master",",",1))//remove trailing comma
    print all traces    //used for debugging
    removefromGraph/w=Master $alltraces

End


This returns an error that the traces are not on the graph. However if I go to the command line and take the printed string as the tracenamelist to removefromgraph, it works fine. How can tracenamelist return a trace name not on graph?
It would be nice if the $ operator worked that way, but it doesn't. It takes a string expression and interprets the contents as a single name, not a list of names.

You need to write a loop that extracts one name from the list and removes that one trace, then loops around to do the next.

Watch out for a gotcha- if you have traces with the same name so that you get trace instance names ("MyWave", "MyWave#1", etc.) then removing the first one ("MyWave") changes the name of the second one from "MyWave#1" to "MyWave". The solution is iterate over the list backwards, from the last in the list to the first.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Would it be faster to create a style for the graph, kill the graph, and then re-invoke the style?

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville