and bpatchers

    Sep 12 2006 | 12:30 am
    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.
    In the javascript in max pdf, the property is used to return the parent patcher. However, I get errors trying to reference from within a bpatcher. Does this only work within subpatchers?
    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.
    function locate(name) { 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; while (owner) { post(; //debug prev = owner; owner = owner.patcher.parentpatcher; //iterate up. } if (prev) { post("top patcher is",; //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[0] + objCoords[0]; y = windowCoords[1] + objCoords[1];
    outlet(0, x,y+13, x+126, y+73); // post(); // post(x, y); }

    • Sep 14 2006 | 6:52 pm
      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?
    • Sep 16 2006 | 4:49 pm
      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)
      please jb
    • Sep 17 2006 | 10:33 pm
      Hi Vade, 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 back online.
      best, wes
    • Sep 18 2006 | 5:22 pm
      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.