Add More Traces By Scripting


miuritan

Recommended Posts

Hi Guru,

I want my user can do add/ remove any traces as they want and following are what i done with unexpected results, pls help to make it works:

// pick the channel which want to be graphed on mainGraph 2D

private string strCurTrace = component.availTraces.strContents

// count the number of traces on mainGraph

v.trace_added_mainGraph[0] += 1

// create the trace name

private string newTrace = "trace_" + v.trace_added_mainGraph[0]

// add this new trace name

component.mainGraph.AddTrace(newTrace)

component.mainGraph.newTrace.strYExpression = strCurTrace

component.mainGraph.newTrace.strLabel = strCurTrace

When i did press button, nothing happened on mainGraph but when i double-click on this mainGraph, i can see there are some New Trace created without strYExpression :(

Thanks.

Link to comment
Share on other sites

The problem is that newTrace is a variable, not the name of the trace. The name of the trace is "trace_" + v.trace_added_mainGraph[0]. If you want to reference that trace in script like you do in the last two lines, you use the name, not "newTrace". So, let's say v.trace_added_mainGraph[0] is just "ABC", making the variable newTrace = "trace_ABC". The last two lines would read:

component.mainGraph.trace_ABC.strYExpression = strCurTrace

etc..

You can do this dynamically if you want using execute:

execute("component.mainGraph." + newTrace + ".strYExpression = strCurTrace")

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.