copy/paste trace formatting

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

 

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.

Tony, what happens if the user changed trace parameters from the command line rather than menu?

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.

In reply to 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.

paste trace formatting, offsets, or the trace itself...

menu "TracePopup", dynamic
    "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

 

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More