<?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: Making a drag &amp;amp; drop script in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Making-a-drag-amp-drop-script/m-p/921211#M107998</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;(and to&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/26800"&gt;@hogi&lt;/a&gt;&amp;nbsp;for your contribution)!&amp;nbsp; I should be able to adapt this for my purposes.&amp;nbsp; And I learned something about Mousetrap, Add Graphics Script, and Name Expr in the process.&lt;/P&gt;
&lt;P&gt;The JMP Community never ceases to amaze me in responsiveness and knowledge.&amp;nbsp; Much appreciated!&lt;/P&gt;</description>
    <pubDate>Wed, 24 Dec 2025 13:13:48 GMT</pubDate>
    <dc:creator>JerryFish</dc:creator>
    <dc:date>2025-12-24T13:13:48Z</dc:date>
    <item>
      <title>Making a drag &amp; drop script</title>
      <link>https://community.jmp.com/t5/Discussions/Making-a-drag-amp-drop-script/m-p/921147#M107991</link>
      <description>&lt;P&gt;Hello, I've been struggling trying to make something like the Drag &amp;amp; Drop interfaces used in (JMP Pro) SEM and Reliability Block Diagrams.&lt;/P&gt;
&lt;P&gt;The idea is to have a pallet of "boxes" down the left side of the screen.&amp;nbsp; I want to grab one of the boxes, drag it into the center area of the screen, drop it, then go grab another box, drag &amp;amp; drop, etc.&lt;/P&gt;
&lt;P&gt;I've tried several ways, including handles and mousetraps.&amp;nbsp; I can get part of the way, but not all the way.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My latest code is shown below, using Mousetrap.&amp;nbsp; I can grab the box in the upper left of the GraphBox, and drag it around the screen, and drop it where I want it.&amp;nbsp; (It turns black when it is dropped.)&amp;nbsp; But then I can't go grab another box.&amp;nbsp; I can only move the box I just dropped.&amp;nbsp; I cannot add another box.&lt;/P&gt;
&lt;P&gt;I'm currently building this as an Application, but happy to change that if it helps.&lt;/P&gt;
&lt;P&gt;Script below shows what I've coded in Application Builder.&amp;nbsp; Attached file contains the entire application.&lt;/P&gt;
&lt;P&gt;I fear there are aspects of Mousetrap and GraphBoxes and Add Graphics Scripts that I just don't grasp.&amp;nbsp; Can anyone help?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// This script is executed when a new module instance is
// created.  The pre-defined object "thisModuleInstance" refers
// to the instance object, but other objects such as boxes and
// scripts have not yet been created.  Variables declared here are
// scoped to the ModuleInstance namespace.

// This special function will receive parameters passed to CreateInstance()
OnModuleLoad({},
);

thisModuleInstance &amp;lt;&amp;lt; Create Objects;

// After this point your module instance objects have been created
// and can be referred to by name (for example, "Button1").



x0=5;
y0=95;
	
	
winref = (this module instance &amp;lt;&amp;lt; Get Box);
// set graph box scales
winref[framebox(1)] &amp;lt;&amp;lt; xaxis(0,100);
winref[framebox(1)] &amp;lt;&amp;lt; yaxis(0,100);

// draw box in upper left corner.
pen color("Green");
winref[framebox(1)] &amp;lt;&amp;lt; add graphics script(
							pen color("Green");
							Line({0,90}, {10,90},{10,100}, {0,100},{0,90}));



winref[framebox(1)] &amp;lt;&amp;lt; Add Graphics Script(

						Mousetrap( 

							// drag script (mouse down)
							(
								// if mouse location is within box in upper left corner, then OK to drag.
									if(
										and(
											x&amp;gt;=x0-5,
											y&amp;gt;=y0-5,
											x&amp;lt;=x0+5,
											y&amp;lt;=y0+5
											),
										(	
											// set x0 and y0 if that were true
											x0 = x;
											y0 = y;
											// redraw the box at current mouse location while mouse button is down
											winref[framebox(1)] &amp;lt;&amp;lt; add graphics script(
												"Front",
												pen color("Green");
												Line({x0-5, y0-5}, {x0+5, y0-5}, {x0+5, y0+5}, {x0-5, y0+5}, {x0-5, y0-5}));
										)
									);
							),

							(
							// mouse up script
								// draw a polygon centered at the current mouse location
								winref[framebox(1)] &amp;lt;&amp;lt; add graphics script(
									polygon({x0-5,y0-5},{x0+5,y0-5},{x0+5,y0+5},{x0-5,y0+5},{x0-5,y0-5})
									);
								// at this point I want to manually reposition the mouse over the original box in the
								// upper left, and grab another box.
								// Instead, all I can do is grab the box I just created and drag it somewhere else.
							)

						);


);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Dec 2025 20:19:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Making-a-drag-amp-drop-script/m-p/921147#M107991</guid>
      <dc:creator>JerryFish</dc:creator>
      <dc:date>2025-12-23T20:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: Making a drag &amp; drop script</title>
      <link>https://community.jmp.com/t5/Discussions/Making-a-drag-amp-drop-script/m-p/921159#M107992</link>
      <description>&lt;P&gt;You most likely do not want to keep adding new graphic scripts all the time as it will end up overwriting your If() and "flood" the framebox&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1766522528220.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/89562i0F0364623795BB1E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1766522528220.png" alt="jthi_0-1766522528220.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;You can build this in much better way, but below is one example what you could possibly do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

rects = {};
x0 = 5;
y0 = 95;
x = .;
y = .;

nw = New Window("Example",
	
	Graph Box(
		Frame Size(200, 200),
		Mousetrap(
			x0 = x;
			y0 = y;
		,
		p = EvalExpr(Polygon(
			{Expr(x0+5), Expr(y0-5)},
			{Expr(x0+5), Expr(y0+5)},
			{Expr(x0-5), Expr(y0+5)},
			{Expr(x0-5), Expr(y0-5)}
		));
		Insert Into(rects, Name Expr(p));
		);
		Pen color("Green");
		Line({0,90}, {10,90},{10,100}, {0,100},{0,90});
		
		If(x &amp;gt;= x0 - 5 &amp;amp; y &amp;gt;= y0 - 5 &amp;amp; x &amp;lt;= x0 + 5 &amp;amp; y &amp;lt;= y0 + 5,
			Pen color("Green");
			Line({x0-5, y0-5}, {x0+5, y0-5}, {x0+5, y0+5}, {x0-5, y0+5}, {x0-5, y0-5});
		);
		
		For(i = 1, i &amp;lt;= N Items(rects), i++,
			Pen Color("Black");
			Eval(rects[i]);
		);
	);
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&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="jthi_1-1766523967638.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/89563i0F98FCB07A4441BC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_1-1766523967638.png" alt="jthi_1-1766523967638.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Added initialization for x and y&lt;/P&gt;</description>
      <pubDate>Wed, 24 Dec 2025 06:49:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Making-a-drag-amp-drop-script/m-p/921159#M107992</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-12-24T06:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Making a drag &amp; drop script</title>
      <link>https://community.jmp.com/t5/Discussions/Making-a-drag-amp-drop-script/m-p/921160#M107993</link>
      <description>&lt;P&gt;&amp;nbsp;I get:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;DisplayBox[EvalContextBox]&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Name Unresolved: x in access or evaluation of 'x' , x/*###*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;at line 26&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;do x&amp;amp;y&amp;nbsp; persist outside the mousetrap?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1766525524905.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/89564iE967B41113B5D41E/image-size/large?v=v2&amp;amp;px=999" role="button" title="hogi_0-1766525524905.png" alt="hogi_0-1766525524905.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;edit&lt;/STRONG&gt;:&lt;BR /&gt;They "persist outside of the Mousetrap"&lt;BR /&gt;- but not forever. It seems they are reset when the mouse button is released:&lt;BR /&gt;&lt;A href="https://community.jmp.com/t5/Discussions/Can-JMP-graphics-have-this-effect/m-p/921213/highlight/true#M107999" target="_blank" rel="noopener"&gt;https://community.jmp.com/t5/Discussions/Can-JMP-graphics-have-this-effect/m-p/921213/highlight/true#M107999&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cool, with the green rectangle, the illusion of "dragging" is very convincing ; )&lt;BR /&gt;Without the green rectangle, it feels much more like: add a black rectangle with every mouse click.&lt;/P&gt;
&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6386912122112w280h280r634" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6386912122112" data-account="6058004218001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6058004218001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6386912122112w280h280r634');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://community.jmp.com/t5/video/gallerypage/video-id/6386912122112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Dec 2025 21:00:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Making-a-drag-amp-drop-script/m-p/921160#M107993</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2025-12-25T21:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Making a drag &amp; drop script</title>
      <link>https://community.jmp.com/t5/Discussions/Making-a-drag-amp-drop-script/m-p/921187#M107997</link>
      <description>&lt;P&gt;I most likely had x and y initialized in memory so it wasn't working. I did update the script with the initialization of x and y and now it seems to work in new JMP session.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Dec 2025 06:50:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Making-a-drag-amp-drop-script/m-p/921187#M107997</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-12-24T06:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Making a drag &amp; drop script</title>
      <link>https://community.jmp.com/t5/Discussions/Making-a-drag-amp-drop-script/m-p/921211#M107998</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;(and to&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/26800"&gt;@hogi&lt;/a&gt;&amp;nbsp;for your contribution)!&amp;nbsp; I should be able to adapt this for my purposes.&amp;nbsp; And I learned something about Mousetrap, Add Graphics Script, and Name Expr in the process.&lt;/P&gt;
&lt;P&gt;The JMP Community never ceases to amaze me in responsiveness and knowledge.&amp;nbsp; Much appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Dec 2025 13:13:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Making-a-drag-amp-drop-script/m-p/921211#M107998</guid>
      <dc:creator>JerryFish</dc:creator>
      <dc:date>2025-12-24T13:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Making a drag &amp; drop script</title>
      <link>https://community.jmp.com/t5/Discussions/Making-a-drag-amp-drop-script/m-p/921219#M108002</link>
      <description>&lt;P&gt;This is an advanced version of &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;'s script:&lt;/P&gt;
&lt;P&gt;- existing boxes can be dragged.&lt;/P&gt;
&lt;P&gt;- no box is created or moved when the user clicks on an area without a box.&lt;/P&gt;
&lt;P&gt;- the initial box at the top acts as an endless reservoir of boxes.&lt;/P&gt;
&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6386914707112w276h280r92" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6386914707112" data-account="6058004218001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6058004218001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6386914707112w276h280r92');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://community.jmp.com/t5/video/gallerypage/video-id/6386914707112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&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 );

squares = {{5, 95}};
x = .;
y = .;
mouseDown = 1;
foundOne = 0;

nw = New Window( "Example", 
	
	Graph Box(
		Frame Size( 200, 200 ),
		Mousetrap(
		// find a neighboring square 
			If( mouseDown,
				x0 = x;
				y0 = y;
		
				If( N Items( squares ),
					kt = KDTable( Matrix( squares ) );
					{row, dist} = kt &amp;lt;&amp;lt; K nearest rows( {1, 10}, Matrix( {x0, y0} ) );
					If( N Items( row ) &amp;amp; dist[1] &amp;lt; 10,
						If( row &amp;gt; 1, // keep the one at the top corner
							Remove From( squares, row[1] )
						);
						foundOne = 1;
					);
				);
			);
			mouseDown = 0;, 
			// mouse relesed -&amp;gt; save the square
			If( foundOne,
				Insert Into( squares, Eval List( {Eval List( {x, y} )} ) )
			);
			
			//reset
			mouseDown = 1;
			foundOne = 0;
			
		);
		
		Pen Color( "Green" );
		Line( {0, 90}, {10, 90}, {10, 100}, {0, 100}, {0, 90} ); // 1st  square to start with
		
		// dragged square 
		If( Not( Is Missing( x ) ) &amp;amp; foundOne, 

			Line( {x - 5, y - 5}, {x + 5, y - 5}, {x + 5, y + 5}, {x - 5, y + 5}, {x - 5, y - 5} )
		);
		

		
		For( i = 1, i &amp;lt;= N Items( squares ), i++,
			Pen Color( "Black" );
			Eval(
				{x0, y0} = squares[i];
				
				Polygon( {x0 + 5, y0 - 5}, {x0 + 5, y0 + 5}, {x0 - 5, y0 + 5}, {x0 - 5, y0 - 5} );
			);
		);
	)
);

&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Dec 2025 21:05:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Making-a-drag-amp-drop-script/m-p/921219#M108002</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2025-12-25T21:05:31Z</dc:date>
    </item>
  </channel>
</rss>

