Quick graph transfer between experiment sessions

This is a complete and more robust rewrite of the Transfer Graphs project by user wings (see https://www.wavemetrics.com/project/TransferGrpahs ), which does not seem to get updated anymore. The idea is to "save" the top graph and recreate it in another Igor session with just two quick menu calls. The source experiment must have been saved in its current state for this to work. Note that something similar could also be achieved by saving a graph copy and merging the graph experiment file into another session.

Other notes and caveats:

  • Details are saved inside the clipboard. Any previous clipboard information is lost.
  • The source experiment gets 'modified' by the creation of a temporary wave (W_WaveList). Don't be surprised when Igor asks you to save the experiment even though you only have copied a graph.
  • A lot of code is spent on catching errors from loading the data. This could get much shorter when / if LoadData supports the /Z flag.
Menu "Windows"
    "Save Top Graph",/Q, SaveTopGraph()
    "Load Saved Graph",/Q, LoadSavedGraph()
End

Function SaveTopGraph()
    String expName = IgorInfo(12)
    if (!strlen(expName))
        Abort "You need to save the experiment before using this functionality."
    endif
    PathInfo home
    String saveRec = "TransferGraph@"+S_Path+expName+"@"+WinName(0,1)+"@"
    GetWindow kwTopWin, wavelist
    Variable i
    Wave/T wList=W_WaveList
    for (i=0; i<DimSize(wList,0); i++)
        saveRec += wList[i][1]+";"
    endfor
    saveRec += "@"+ReplaceString("root:",WinRecreation("",0),":")
    PutScrapText saveRec
    KillWaves wList
    return 0
End

Function LoadSavedGraph()
    String loadRec = GetScrapText()
    if (CmpStr(StringFromList(0,loadRec,"@"),"TransferGraph"))
        Abort "You need to first save a graph."
    endif
    String filePath = StringFromList(1,loadRec,"@")
    String grName   = StringFromList(2,loadRec,"@")
    String wList    = StringFromList(3,loadRec,"@")
    String grRec    = StringFromList(4,loadRec,"@")
   
    DFREF saveDFR = GetDataFolderDFR()
    SetDataFolder root:
    NewDataFolder/O/S $grName
    DFREF base = root:$grName
   
    Variable i, j
    for (i=0; i<ItemsInList(wList); i++)
        String curr = ReplaceString("'",StringFromList(i,wList),"")
        String path = ParseFilePath(1, curr, ":", 1, 0)
        if (strlen(path))
            for (j = 0; j < ItemsInList(path,":"); j++)
                NewDataFolder/O/S $StringFromList(j,path,":")
            endfor
        endif
       
        DebuggerOptions
        Variable DebugOn = V_debugOnError, err = 0
        DebuggerOptions debugOnError=0
        try
            LoadData/Q/O/S=path/J=ParseFilePath(0, curr, ":", 1, 0)+";" filePath;   AbortOnRTE
        catch
            err = GetRTError(1)
            Print "Could not load the data for the graph. Maybe the source experiment was not saved in its current state. Error: " + GetErrMessage(err, 3)
        endtry
        DebuggerOptions debugOnError=DebugOn
        if (err)
            SetDataFolder saveDFR
            return -1
        endif
       
        SetDataFolder base
    endfor
   
    for (i=2; i<ItemsInList(grRec,"\r")-1; i++)
        String cmd = StringFromList(i,grRec,"\r")
        if(StringMatch(cmd,"*String*"))
            continue
        endif
        if(StringMatch(cmd,"*SetDataFolder fldrSav*"))
            SetDataFolder base
            continue
        endif
        Execute cmd
    endfor
   
    SetDataFolder saveDFR
    return 0
End

 

GraphTransfer_v1.ipf (2.64 KB)

Great. I have forgotten the password and for some other reason, I could not log in forums until now. That is why no update since then...

Thanks for your effort!

Hi wings, welcome back! Feel free to update your project with above code if you like. I found that some things do not yet work as expected. For example, it is currently problematic to load graphs with the same name from different experiments or there are problems if the file has not been saved after changes have been made. Both problems can be easily fixed with some effort, but so far it worked 'good enough' for me.

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More