Add a textbox containing a graph's name or title

// Adds a textbox containing the graph's name or title.

// Example
// Make/O/N=10 wave0=p
// Display wave0 as "Graph of wave0"
// AddGraphTitleTextbox("")

Function/S WindowTitle(WindowName) // Returns the title of a window given its name.
        String WindowName // Name of graph, table, layout, notebook or control panel.

        String RecMacro
        Variable AsPosition, TitleEnd
        String TitleString

        if (strlen(WindowName) == 0)
                WindowName=WinName(0,1)         // Name of top graph window
        endif

        if (wintype(WindowName) == 0)
                return ""                       // No window by that name
        endif

        RecMacro = WinRecreation(WindowName, 0)
        AsPosition = strsearch(RecMacro, " as \"", 0)
        if (AsPosition < 0)
                TitleString = WindowName        // No title, return name
        else
                AsPosition += 5                 // Found " as ", get following quote mark
                TitleEnd = strsearch(RecMacro, "\"", AsPosition)
                TitleString = RecMacro[AsPosition, TitleEnd-1]
        endif

        return TitleString
End

Function AddGraphNameTextbox(graphName)
    String graphName                // "" for top visible graph
   
    if (strlen(graphName) == 0)
        graphName = WinName(0, 1, 1)
    endif
    if (strlen(graphName) == 0)
        return -1                   // There are no graphs.
    endif
   
    DoWindow $graphName
    if (V_flag == 0)
        return -1                   // There is no graph with that name.
    endif
   
    String text
    sprintf text, "Graph name is %s", graphName
    Textbox /C/N=GraphName /W=$graphName text
    return 0
End

Function AddGraphTitleTextbox(graphName)
    String graphName                // "" for top visible graph
   
    if (strlen(graphName) == 0)
        graphName = WinName(0, 1, 1)
    endif
    if (strlen(graphName) == 0)
        return -1                   // There are no graphs.
    endif
   
    DoWindow $graphName
    if (V_flag == 0)
        return -1                   // There is no graph with that name.
    endif
   
    String title = WindowTitle(graphName)
       
    String text
    sprintf text, "%s", title
    Textbox /C/N=GraphTitle /W=$graphName text
    return 0
End

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More