<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Graph box Frame Reference gets 'lost' when adding a graphics Script. in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471967#M71646</link>
    <description>&lt;P&gt;The parameter &lt;EM&gt;WaferDiameter&lt;/EM&gt; in the function &lt;EM&gt;MakeWaferMap&lt;/EM&gt; only exists while the function is running. The formula supplied to &amp;lt;&amp;lt;addGraphicsScript will be unhappy with that variable later, when the graph redraws and tries to use it.&lt;/P&gt;
&lt;P&gt;I also like the eval(evalexpr( ... expr() ... expr() ... ) ) method for casting the transient variables into stone, mostly because the JSL editor will still do all of the syntax checking for ( and ).&lt;/P&gt;</description>
    <pubDate>Tue, 22 Mar 2022 11:47:15 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2022-03-22T11:47:15Z</dc:date>
    <item>
      <title>Graph box Frame Reference gets 'lost' when adding a graphics Script.</title>
      <link>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471921#M71639</link>
      <description>&lt;P&gt;I am trying to draw a simple Wafermap which works fine with the following code.&lt;/P&gt;&lt;P&gt;However, when I substitute variables in for the numbers I get a missing reference error and can't for the life of me understand why this is happening. I need some JSL Expert Wisdom :)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;F_makeWaferMap = function({myScale, myWhiteSpace, myWaferDiameter},{},

	myKeepOutZone = 2000;
	
	myGraphBox = graphBox( 
		frameSize( (myWaferDiameter/2)/myScale, (myWaferDiameter/2)/myScale ), 
		xScale( -myWhiteSpace, myWaferDiameter + myWhiteSpace),
		yScale( -myWhiteSpace, myWaferDiameter + myWhiteSpace)
					
	);
	frame = myGraphBox[FrameBox(1)];
	frame &amp;lt;&amp;lt; Add Graphics Script(penColor( "red" ); circle( {150000,150000}, 150000));
	frame &amp;lt;&amp;lt; Add Graphics Script(penColor( "red" ); circle( {150000,150000}, 150000-2000));
	
	return(myGraphBox);
);

myWmDispObj = F_makeWaferMap(200, 20000, 300000);		// Scale, Whitespace, Wafer Diameter
newWindow("Test", vListBox(myWmDispObj));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="thickey_0-1647940685853.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/41019iF3F5FA94E74771C0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="thickey_0-1647940685853.png" alt="thickey_0-1647940685853.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I am happily making references to the Frame Box as you can see from the log:&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="thickey_1-1647940813033.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/41020iDC2927C13A39326F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="thickey_1-1647940813033.png" alt="thickey_1-1647940813033.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;So, now lets substitute in some variables.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	frame &amp;lt;&amp;lt; Add Graphics Script(penColor( "red" ); circle( {myWaferDiameter/2, myWaferDiameter/2}, myWaferDiameter/2));
	frame &amp;lt;&amp;lt; Add Graphics Script(penColor( "red" ); circle( {myWaferDiameter/2, myWaferDiameter/2}, (myWaferDiameter/2) - myKeepOutZone));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I get the following Error, suggesting I have lost the reference to my passed in variables when I try to add them to the frame box.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="thickey_2-1647940929283.png" style="width: 895px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/41021i570C63144EE49873/image-dimensions/895x123?v=v2" width="895" height="123" role="button" title="thickey_2-1647940929283.png" alt="thickey_2-1647940929283.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I'm stumped :)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 18:13:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471921#M71639</guid>
      <dc:creator>thickey</dc:creator>
      <dc:date>2023-06-09T18:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: Graph box Frame Reference gets 'lost' when adding a graphics Script.</title>
      <link>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471940#M71640</link>
      <description>&lt;P&gt;You might have to use some Eval(EvalExpr()) magic&amp;nbsp;&lt;LI-MESSAGE title="Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute" uid="48998" url="https://community.jmp.com/t5/JSL-Cookbook/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/m-p/48998#U48998" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	Eval(EvalExpr(
		frame &amp;lt;&amp;lt; Add Graphics Script(
			Pen Color("red");
			Circle({Expr(myWaferDiameter) / 2, Expr(myWaferDiameter) / 2}, Expr(myWaferDiameter) / 2);
		);
	));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Mar 2022 09:38:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471940#M71640</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-03-22T09:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Graph box Frame Reference gets 'lost' when adding a graphics Script.</title>
      <link>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471942#M71642</link>
      <description>&lt;P&gt;Hi Jarmo, yes, I can simply do an eval(parse()), substituting my variable into the string to be converted to JSL but it's not the 'proper' way to go in my opinion.. Surely, there is a mechanism to this in a more ;direct' way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;eval(parse("frame &amp;lt;&amp;lt; Add Graphics Script(penColor( \!"red\!" ); circle( {150000,150000}, " || char(myWaferDiameter/2) || "))"));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Mar 2022 10:17:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471942#M71642</guid>
      <dc:creator>thickey</dc:creator>
      <dc:date>2022-03-22T10:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: Graph box Frame Reference gets 'lost' when adding a graphics Script.</title>
      <link>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471962#M71643</link>
      <description>&lt;P&gt;I would never use Evil(Parse()) if it can be avoided (and in this case it can be) by using Eval(EvalExpr()) or substitute. At least I don't know of any other methods besides these (or if I do they are more complicated), how I could replace values in some platforms/jmp functions with values (like in Formulas). My preferred method is EvalExpr() as it is fairly easy to debug and it still gives you JSL highlighting in script editor (parse method wont).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

F_makeWaferMap = function({myScale, myWhiteSpace, myWaferDiameter},{},

	myKeepOutZone = 2000;
	
	myGraphBox = graphBox( 
		frameSize( (myWaferDiameter/2)/myScale, (myWaferDiameter/2)/myScale ), 
		xScale( -myWhiteSpace, myWaferDiameter + myWhiteSpace),
		yScale( -myWhiteSpace, myWaferDiameter + myWhiteSpace)
					
	);
	frame = myGraphBox[FrameBox(1)];

	expr_sub = Substitute(
		Expr(frame &amp;lt;&amp;lt; Add Graphics Script(
			penColor("red"); 
			circle({myWaferDiameter/2, myWaferDiameter/2}, myWaferDiameter/2)
		)),
		Expr(myWaferDiameter),
		myWaferDiameter
	);
	
	expr_evalexpr = EvalExpr(
		frame &amp;lt;&amp;lt; Add Graphics Script(
			penColor( "red" ); 
			circle({Expr(myWaferDiameter)/2, Expr(myWaferDiameter)/2}, (Expr(myWaferDiameter)/2) - Expr(myKeepOutZone)));
	);
	
	show(expr_sub);
	show(expr_evalexpr);

	Eval(expr_sub);
	Eval(expr_evalexpr);
	
	return(myGraphBox);
);

myWmDispObj = F_makeWaferMap(200, 20000, 300000);		// Scale, Whitespace, Wafer Diameter
newWindow("Test", vListBox(myWmDispObj));
Show(myWmDispObj &amp;lt;&amp;lt; Get Graphics Script);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Mar 2022 10:40:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471962#M71643</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-03-22T10:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Graph box Frame Reference gets 'lost' when adding a graphics Script.</title>
      <link>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471967#M71646</link>
      <description>&lt;P&gt;The parameter &lt;EM&gt;WaferDiameter&lt;/EM&gt; in the function &lt;EM&gt;MakeWaferMap&lt;/EM&gt; only exists while the function is running. The formula supplied to &amp;lt;&amp;lt;addGraphicsScript will be unhappy with that variable later, when the graph redraws and tries to use it.&lt;/P&gt;
&lt;P&gt;I also like the eval(evalexpr( ... expr() ... expr() ... ) ) method for casting the transient variables into stone, mostly because the JSL editor will still do all of the syntax checking for ( and ).&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 11:47:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471967#M71646</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2022-03-22T11:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Graph box Frame Reference gets 'lost' when adding a graphics Script.</title>
      <link>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471968#M71647</link>
      <description>&lt;P&gt;Hello, I am not exactly sure why this works but would appreciate any insights. It seems that if you set another variable in your function (in this case just myWaferDiameter1) it seems to pass to the frame messages just fine?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 );

F_makeWaferMap = function({myScale, myWhiteSpace, myWaferDiameter},{},
	
	myWaferDiameter1 = myWaferDiameter; //new variable here?
	
	myKeepOutZone = 2000;
	&lt;BR /&gt;    //Use myWaferDiameter1 instead
	myGraphBox = graphBox( 
		frameSize( (myWaferDiameter1/2)/myScale, (myWaferDiameter1/2)/myScale ), 
		xScale( -myWhiteSpace, myWaferDiameter1 + myWhiteSpace),
		yScale( -myWhiteSpace, myWaferDiameter1 + myWhiteSpace)
					
	);
	
	frame = myGraphBox[FrameBox(1)];&lt;BR /&gt;    
	frame &amp;lt;&amp;lt; Add Graphics Script(penColor( "red" ); circle( {myWaferDiameter1/2, myWaferDiameter1/2}, myWaferDiameter1/2));
	frame &amp;lt;&amp;lt; Add Graphics Script(penColor( "red" ); circle( {myWaferDiameter1/2, myWaferDiameter1/2}, (myWaferDiameter1/2) - myKeepOutZone));

	return(myGraphBox);
	
);

myWmDispObj = F_makeWaferMap( 200, 20000, 300000 );		// Scale, Whitespace, Wafer Diameter 
newWindow("Test", vListBox( myWmDispObj ));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Mar 2022 11:51:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471968#M71647</guid>
      <dc:creator>Joseph_Reese</dc:creator>
      <dc:date>2022-03-22T11:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: Graph box Frame Reference gets 'lost' when adding a graphics Script.</title>
      <link>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471991#M71650</link>
      <description>&lt;P&gt;Joseph, I noticed this also but like you I don't understand why a locally (to the function) generated variable works, whereas one passed in does not. V.Interesting.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 13:19:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/471991#M71650</guid>
      <dc:creator>thickey</dc:creator>
      <dc:date>2022-03-22T13:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Graph box Frame Reference gets 'lost' when adding a graphics Script.</title>
      <link>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/472057#M71667</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/8747"&gt;@Joseph_Reese&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works because variables defined inside the function are not, by default, local to that function. If you use delete symbols() before and show symbols() after running that script, you will find&amp;nbsp;myWaferDiameter1 is now a global variable. Whenever writing functions I recommend using {defaultlocal} as the second argument for this reason, or to name all variables created in the function in that parameter so they are all local to that function call only.&amp;nbsp; If you use default local you will find the error re-appears since the variable no longer exists when the graph is drawn.&amp;nbsp; As &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;points out, you can resolve this by evaluating the variable in the function context and then passing the value to the graph. As&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;suggested, parameters to the function are also removed once the function finishes running, which is what caused the original problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, to the original question from&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/24222"&gt;@thickey&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the original example and when using a local variable in the function or as an argument to a function, the value&amp;nbsp;myWaferDiameter exists in the function's local namespace until the function finishes running at which time it is removed from memory.&amp;nbsp; Since the graph is not drawn until after the function is finished running it cannot access the variable's value. To solve this, evaluate the variable in the context of the function.&amp;nbsp; I also prefer the method of doing this that&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;described:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE class="language-jsl"&gt;&lt;CODE&gt;	Eval(EvalExpr(
		frame &amp;lt;&amp;lt; Add Graphics Script(
			Pen Color("red");
			Circle({Expr(myWaferDiameter) / 2, Expr(myWaferDiameter) / 2}, Expr(myWaferDiameter) / 2);
		);
	));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When a variable is defined in the function that is a global variable, that variable exists until it is either deleted (using delete symbols() for example) or until JMP is restarted. So, when the window is drawn after the function finishes, it can still access the variable. This&amp;nbsp;&lt;EM&gt;is&lt;/EM&gt; a solution but it is more likely to cause errors in future code since different windows or scripts could interact with each other unexpectedly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: As a shameless plug for my own wish list item, I think evaluating myWaferDiamer in right context can be made slightly more intuitive by introducing a new function:&amp;nbsp;&lt;LI-MESSAGE title="Introduce Eval Expr First() as a new wrapper for Eval( Eval Expr( ... ) )" uid="278599" url="https://community.jmp.com/t5/JMP-Wish-List/Introduce-Eval-Expr-First-as-a-new-wrapper-for-Eval-Eval-Expr/m-p/278599#U278599" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-idea-thread lia-fa-icon lia-fa-idea lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 19:05:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Graph-box-Frame-Reference-gets-lost-when-adding-a-graphics/m-p/472057#M71667</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2022-03-22T19:05:21Z</dc:date>
    </item>
  </channel>
</rss>

