Location of object when selected

Apr 13, 2007 at 5:12pm

Location of object when selected

I want to get information about objects as I drag them around a window.

First I want to select a group of objects that have a single named button.
As I drag I want to show the position of the upper left corner of that
button.

I am guessing this is a javascript thing. I know how to poll all objects in
a window and cull out just the named buttons. This was posted some time
ago.

/*
simple example of iterating through all objects in a patch
*/

// set up inlets/outlets/assist strings
outlets = 5;
setoutletassist(4,”begin (bang)”);
setoutletassist(3,”parent patcher name (symbol)”);
setoutletassist(2,”box classname (symbol)”);
setoutletassist(1,”box scripting name (list)”);
setoutletassist(0,”box rect (list)”);

function bang()
{
outlet(4,”bang”);
this.patcher.apply(iterfun);
}

function iterfun(b)
{
outlet(3, b.patcher.name);
outlet(2, b.maxclass);
outlet(1, b.varname);
outlet(0, b.rect);

return true;
}
iterfun.local=1; // keep private

Can I test in iterfun.local whether an object is selected?

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson

#31365
Apr 13, 2007 at 8:39pm

Here is a patch that illustrates my goal.

In brief, I want to click on object in a LOCKED patcher and have max tell me
the name of that object so that I can move the object and associated objects
in a group with the mouse.

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 188 447 44 196617 zl rot 1;
#P newex 476 686 209 196617 sprintf script move amessage[%ld] %ld %ld;
#P newex 256 684 208 196617 sprintf script move sometext[%ld] %ld %ld;
#P newex 43 686 199 196617 sprintf script move abutton[%ld] %ld %ld;
#P message 567 436 34 196617 0 0 3;
#P newex 573 496 32 196617 print;
#P newex 573 471 44 196617 zl rot 1;
#P window setfont “Sans Serif” 24.;
#P number 425 201 96 24 1 3 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont “Sans Serif” 9.;
#N vpatcher 20 74 620 474;
#P outlet 305 190 15 0;
#P outlet 217 191 15 0;
#P inlet 211 92 15 0;
#P pop;
#P newobj 131 123 56 196617 p message;
#P objectname amessage[3];
#N vpatcher 20 74 620 474;
#P outlet 220 183 15 0;
#P inlet 219 105 15 0;
#P pop;
#P newobj 147 107 37 196617 p text;
#P objectname sometext[3];
#P button 131 107 15 0;
#P objectname abutton[3];
#P window setfont “Sans Serif” 24.;
#P number 361 620 93 24 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 262 620 93 24 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont “Sans Serif” 9.;
#P newex 262 596 40 196617 unpack;
#P window setfont “Sans Serif” 12.;
#P comment 245 153 141 196620 What I need to know;
#P window setfont “Sans Serif” 9.;
#P newex 139 425 29 196617 gate;
#P newex 282 362 66 196617 modifiers;
#N vpatcher 20 74 620 474;
#P outlet 305 190 15 0;
#P outlet 217 191 15 0;
#P inlet 211 92 15 0;
#P pop;
#P newobj 79 186 56 196617 p message;
#P objectname amessage[2];
#N vpatcher 20 74 620 474;
#P outlet 220 183 15 0;
#P inlet 219 105 15 0;
#P pop;
#P newobj 95 170 37 196617 p text;
#P objectname sometext[2];
#P button 79 170 15 0;
#P objectname abutton[2];
#N vpatcher 20 74 620 474;
#P outlet 305 190 15 0;
#P outlet 217 191 15 0;
#P inlet 211 92 15 0;
#P pop;
#P newobj 41 127 56 196617 p message;
#P objectname amessage[1];
#N vpatcher 20 74 620 474;
#P outlet 220 183 15 0;
#P inlet 219 105 15 0;
#P pop;
#P newobj 57 111 37 196617 p text;
#P objectname sometext[1];
#P button 41 111 15 0;
#P objectname abutton[1];
#P newex 158 282 161 196617 t 1 b b b;
#P newex 158 260 48 196617 loadbang;
#P message 524 645 40 196617 0 0 16;
#P newex 477 666 76 196617 vexpr $i1+$i2;
#P message 261 554 40 196617 0 16 0;
#P newex 145 610 76 196617 vexpr $i1+$i2;
#P message 221 332 42 196617 mode 1;
#P newex 189 420 57 196617 pack 0 0 0;
#P toggle 158 393 15 0;
#P newex 146 551 29 196617 gate;
#P toggle 158 309 15 0;
#P newex 158 331 52 196617 metro 50;
#P newex 158 361 114 196617 mousestate;
#B color 5;
#N thispatcher;
#Q end;
#P newobj 34 728 61 196617 thispatcher;
#P comment 244 79 156 196617 all off these objects are named;
#P window linecount 4;
#P comment 246 97 165 196617 with the patcher locked I want to control-click
on the text patcher in each group to drag all three objects to the mouse
position;
#P window setfont “Sans Serif” 12.;
#P window linecount 1;
#P comment 245 55 141 196620 What I already know;
#P window setfont “Sans Serif” 9.;
#P window linecount 5;
#P comment 246 175 159 196617 How can Idetect a mouse click on a particular
group and retrieve the names of the selected objects to pass into script
messages for thispatcher;
#P window setfont “Sans Serif” 24.;
#P window linecount 2;
#P comment 477 65 168 196632 control click the mouse;
#P connect 41 0 9 1;
#P connect 11 0 41 0;
#P connect 40 0 5 0;
#P connect 9 0 38 0;
#P connect 9 0 13 0;
#P connect 9 0 28 0;
#P connect 9 0 15 0;
#P connect 39 0 5 0;
#P connect 38 0 5 0;
#P connect 13 0 39 0;
#P connect 15 0 40 0;
#P connect 35 0 36 0;
#P connect 37 0 35 0;
#P connect 19 0 21 0;
#P connect 20 0 21 0;
#P connect 21 1 20 0;
#P connect 25 3 26 0;
#P connect 26 0 9 0;
#P connect 23 0 24 0;
#P connect 22 0 24 0;
#P connect 17 0 18 0;
#P connect 18 0 8 0;
#P connect 8 0 7 0;
#P connect 7 0 6 0;
#P connect 12 0 6 0;
#P connect 6 0 10 0;
#P connect 10 0 26 1;
#P connect 24 1 23 0;
#P connect 6 1 11 0;
#P connect 14 0 13 1;
#P connect 6 2 11 1;
#P fasten 18 2 14 0 263 454 266 454;
#P connect 18 1 12 0;
#P connect 34 0 11 2;
#P connect 7 0 25 0;
#P fasten 18 3 16 0 313 332 529 332;
#P connect 16 0 15 1;
#P connect 31 0 33 0;
#P connect 32 0 33 0;
#P connect 33 1 32 0;
#P connect 28 0 29 0;
#P connect 28 1 30 0;
#P window clipboard copycount 42;

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson

#101810

You must be logged in to reply to this topic.