this.patcher.box and bpatchers
I am attempting to create a JS, that when used will discover the absolute position of an named object, regardless of whether its in a batcher, a few bpatchers, or in the parent itself.
A workaround ive found is to use this.patcher.parentpatcher,which seems to resolve parent bpatchers properly. However, it stops once it reaches the patch that contains the bpatcher, (ie, only one level above), and will not iterate to any other parent patchers.
The following code works properly when called from either the main patch, or the parent patch, but no futher above the patcher heirarchy.
I am obviously misunderstanding something. Id love a pointer in the right direction.
obj = this.patcher.getnamed(name);
objCoords= obj.rect; // get the cordinates from within the objects patch
windowCoords = this.patcher.wind.location; //get the window coords
prev = 0;
owner = this.patcher.parentpatcher;
prev = owner;
owner = owner.patcher.parentpatcher; //iterate up.
post("top patcher is", prev.name); //debug
windowCoords = prev.wind.location; // set the window coords to the topmost window
// get our x/y position from window and local coords
x = windowCoords + objCoords;
y = windowCoords + objCoords;
outlet(0, x,y+13, x+126, y+73);
// post(x, y);
So, there is no way to get these coordinates, or, is there a way to get the asbolute screen coordinates of any arbitrary named object?
If I have something like
/main patch/bpatcher/bpatcher/bpatcher/named item
and I want to get the global (or hell relative from main patch) location of ‘named item’, with arbitrary amount of nested bpatchers, I cant?
Anyone want to be my personal hero?
Would you post a complete example, please? Your email is slightly, er, difficult to comprehend, in terms of mocking up something to test and/or fix. I’d like:
A patch in which the js works
A patch in which the js does not work
with the JS
in a folder
in an archive
on a website (or in my mailbox)
I’ve attached a zip file with a JS, 2 bpatchers, and a main patch.
One of the bpatchers has a nested bpatcher as well. The patch shows
how to get absolute coordinates of max objects in batchers. This is
all using the maxobject.rect property. Hopefully the attachment gets
posted. If not, I’ll repost it tommorrow when I can get my computer
Ok, so I don;t think the attachment went through. Here’s a link to the file:
On the matter of ‘having to find the parent window to get global
coordinates’. I think this patch pretty clearly demonstrates that
this is not the case. I never get the coordinates of the windows and
am perfectly capable of getting the location of a double nested object
(located in a bpatcher in a bpatcher) with the rect property. Now, if
you want to know where it is in screen coordinates, you will have to
get the x, y location of the main window, but *only* the main window.
This is not such a big deal as it is trivial to access the main window
that the JS object is located in.