Adding graphs in a window embedded in a panel
Ann
Hi all,
Just a quick question, I am trying to embed a graph in a subwindow embedded in a panel. For the panel name, I am using $kPanelName. Why is it not working? If I use the exact name for the panel and the sub window, everything is fine. If I use the following code section, I get an error message which says there is no graph named on that.
Thanks.
Display/W=(10,10,100,100)/K=3/HOST=$kPanelName/N=myGraph
AppendToGraph/W=$kPanelName#myGraph y vs x
AppendToGraph/W=$kPanelName#myGraph y vs x
Your code seems to suffer a bit from $-confusion. The following code snippet works here and hopefully illustrates how to do it:
string host, subPanel, subGraphInSubPanel
NewPanel
host = S_name
NewPanel/HOST=$host
subPanel = host + "#" + S_name
Display/HOST=$subPanel
subGraphInSubPanel = subPanel + "#" + S_name
End
You can also pass a custom name via /N. The idea is that you build the window path as you go with always the same pattern.
May 1, 2023 at 01:05 pm - Permalink
The problem is that subwindow paths do not support string constants. Assuming you have a string constant like this:
StrConstant kPanelName = "MyPanel"
AppendToGraph/W=$kPanelName#myGraph jack
// This works
String tmp = kPanelName
AppendToGraph/W=$tmp#myGraph jack
May 1, 2023 at 05:49 pm - Permalink
It seems to be a parsing issue- the compiler doesn't know where the string expression ends. This compiles:
Function test()
Wave jack
AppendToGraph/W=$(kPanelName)#myGraph jack
end
I'm not really certain what the compiler is doing when it parses the expression, but I find it's pretty common that you need to help the compiler parse an expression by adding some parentheses. In this case, it makes it clear that the string expression that the $ operator applies to is just the string constant.
May 2, 2023 at 09:22 am - Permalink
@Howard: Thanks for pointing the error out.
Our coding conventions [1] have the entry "Don’t mix
$
with other expressions as it makes the code too hard to read". As both the compiler and humans can easily get into trouble at complex expressions with $.[1]: https://docs.byte-physics.de/igor-pro-coding-conventions/coding_convent…
May 2, 2023 at 09:38 am - Permalink
Thanks all for the information and suggestions.
Yes, I had a string constant (StrConstant kPanelName = "MyPanel") which I used to name the base panel and were trying to embed subwindows in it. It would be better if Igor could use a string constant to refer a subwindow in the way I was trying to do because that bit of code looks simple and potential to work.
May 3, 2023 at 08:52 am - Permalink