
copy/paste trace formatting

tony
Tue, 01/19/2021 - 10:55 am
Does this exist somewhere? I had a quick look around and couldn't find it outside of a feature request in the wishlist forum.
menu "TracePopup", dynamic
"Copy Trace Formatting", /Q
SelectString(cmpstr(GetScrapText()[0,10], "RECREATION:")==0, "", "Paste Trace Formatting"), /Q
end
function CopyTraceFormatting()
GetLastUserMenuInfo
string s = TraceInfo(S_graphName,S_traceName,0)
PutScrapText s[strsearch(s, "RECREATION:", 0),Inf]
end
function PasteTraceFormatting()
GetLastUserMenuInfo
string s = GetScrapText()[11,Inf]
int numCmd = ItemsInList(s)
int i
for(i=0;i<numCmd;i++)
Execute /Q/Z "ModifyGraph "+ReplaceString("(x)", StringFromList(i, s), "("+S_traceName+")", 0, 1)
endfor
end
"Copy Trace Formatting", /Q
SelectString(cmpstr(GetScrapText()[0,10], "RECREATION:")==0, "", "Paste Trace Formatting"), /Q
end
function CopyTraceFormatting()
GetLastUserMenuInfo
string s = TraceInfo(S_graphName,S_traceName,0)
PutScrapText s[strsearch(s, "RECREATION:", 0),Inf]
end
function PasteTraceFormatting()
GetLastUserMenuInfo
string s = GetScrapText()[11,Inf]
int numCmd = ItemsInList(s)
int i
for(i=0;i<numCmd;i++)
Execute /Q/Z "ModifyGraph "+ReplaceString("(x)", StringFromList(i, s), "("+S_traceName+")", 0, 1)
endfor
end

Forum

Support

Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
See WaveMetrics Procedures:Graph Utility Procs.ipf. Includes CopyTraceSettings(), CopyAxisSettings(), CopyImageSettings() and CopyContourSettings().
Has a number of other useful utilities related to getting characteristics of graphs.
It's pretty old. Probably could use some modern polish.
January 20, 2021 at 09:51 am - Permalink
Tony, what happens if the user changed trace parameters from the command line rather than menu?
January 20, 2021 at 10:11 am - Permalink
In reply to Tony, what happens if the… by s.r.chinn
the trace parameters are read from traceinfo. It doesn't matter how they were set, it's the current properties of the trace that are copied. unless I'm missing something.
January 20, 2021 at 12:22 pm - Permalink
Tony's right- TraceInfo returns the current state of the data structures. Note that it can return stale info in a function because certain things are updated during drawing, a running function suppresses redrawing. If you use ModifyGraph, SetAxis, etc., in a function, call DoUpdate before TraceInfo.
January 20, 2021 at 01:36 pm - Permalink
In reply to Tony, what happens if the… by s.r.chinn
I'm realizing that I should have been more clear about how the snippet is used:
right click on a trace and select 'copy trace formatting', then right click on a different trace and select 'paste trace formatting'.
A more useful version might have options to paste offset settings separately from line/marker/color etc.
January 21, 2021 at 09:28 am - Permalink
In that case, there should be no trouble with stale data.
January 21, 2021 at 09:49 am - Permalink
paste trace formatting, offsets, or the trace itself...
"Copy Trace", /Q
SelectString(cmpstr(GetScrapText()[0,5], "YWAVE:")==0, "", "Paste Trace Formatting"), /Q, PasteTraceFormatting(2)
SelectString(cmpstr(GetScrapText()[0,5], "YWAVE:")==0, "", "Paste Trace Offsets"), /Q, PasteTraceFormatting(1)
end
menu "GraphPopup", dynamic
SelectString(cmpstr(GetScrapText()[0,5], "YWAVE:")==0, "", "Paste Trace"), /Q
end
function CopyTrace()
GetLastUserMenuInfo
wave w = TraceNameToWaveRef(S_graphName,S_traceName)
string s = "YWAVE:" + GetWavesDataFolder(w,4) + ";" + TraceInfo(S_graphName,S_traceName,0)
PutScrapText s
end
function PasteTrace()
string s = "", cmd = "AppendToGraph", info = GetScrapText()
cmd += StringByKey("AXISFLAGS", info, ":", ";") + " "
cmd += StringByKey("YWAVE", info, ":", ";") + StringByKey("YRANGE", info, ":", ";")
s = StringByKey("XWAVE", info, ":", ";")
if (strlen(s))
cmd += " vs " + StringByKey("XWAVEDF", info, ":", ";") + s + StringByKey("XRANGE", info, ":", ";")
endif
execute cmd
s=StringByKey("ERRORBARS", info, ":", ";")
if (strlen(s))
execute s
endif
// figure out trace name - hopefully the last 'normal' trace is the one we just added
s = TraceNameList("",";",1)
string tracename = StringFromList(itemsinlist(s)-1, s)
// apply formatting
s = info[strsearch(info, "RECREATION:", 0) + 11, Inf]
int i
int numCmd = itemsinlist(s)
for(i=0;i<numCmd;i++)
cmd = StringFromList(i, s)
if (!stringmatch(cmd, "offset(x)=*"))
Execute /Q/Z "ModifyGraph " + ReplaceString("(x)", cmd, "("+traceName+")", 0, 1)
endif
endfor
end
function PasteTraceFormatting(int WhichCmds)
GetLastUserMenuInfo
string s = GetScrapText(), cmd = ""
s = s[strsearch(s, "RECREATION:", 0) + 11, Inf]
int numCmd = ItemsInList(s)
int i
for(i=0;i<numCmd;i++)
cmd = StringFromList(i, s)
if ((WhichCmds&1) && cmpstr(cmd[0,9], "offset(x)=")==0) // bit 0, offsets
Execute /Q/Z "ModifyGraph " + ReplaceString("(x)", cmd, "("+S_traceName+")", 0, 1)
elseif((WhichCmds&2) && cmpstr(cmd[0,9], "offset(x)="))
Execute /Q/Z "ModifyGraph " + ReplaceString("(x)", cmd, "("+S_traceName+")", 0, 1)
endif
endfor
end
January 25, 2021 at 01:28 pm - Permalink