Is it possible to move objects in a locked patch with js ?

    Jan 19 2010 | 2:13 am
    I'm trying to get my bearings on my first few js patches, and here I've gotten stuck. I've made a patch that creates bpatchers and gives them scripting names in sequential order, connecting the first to the second..and so on. I'm trying to make the patch so if you move the second bpatcher above the first, the connections change order, so 2 goes into 1... that for right now isnt the trouble.... If the bpatchers can't be moved while the patch is locked, the idea is less enticing and I'll have to figure something else out. Any advice.. ? Thanks !

    • Jan 19 2010 | 2:20 am
      Hmm.... I don't remember if I've tried moving js objects from within a locked patch - but I've certainly created new objects galore inside locked patches without an issue.
      I tend to think that the JS stuff doesn't respect locked-ness - that's a UI thing only.
      Are you saying that you have code that runs correctly in an unlocked patch, and then fails when you lock the patch and try again? Can you post your code here?
    • Jan 19 2010 | 2:22 am
      You can use javascript to update the rect/patching_rect/presentation_rect attributes just as you would do from max with messages. This will work even if the patcher is locked. However you might stumble upon a few problems when scripting [bpatcher]s as they don't seem to play fair. If you search the javascript forum you should find all the answers you need though. If you're still having trouble then perhaps post a patch and some code to show us what you have so far.
    • Jan 19 2010 | 2:59 am
      I think i figured out what I needed to. It is entirely possible. the 'script offset' to thispatcher works. Thanks for your quick replies. and a short follow up.. I tried to use mousestate in my bpatchers to give me their relative position to one another so their connections can change... it was troubling. But I found an external I've never used called [posit], in the Jash library which can query x-y coordinates of objects with scripting names. Does anyone know how to do this without externals? Luke, what have you run into with bpatchers and js that caused trouble ? i'm almost depending on it for this program. so any heads up would be appreciated. Luke, you answer a lot of questions for me in this forum. I should have gotten you a christmas present.
    • Jan 20 2010 | 1:40 am
      Maybe I imagined it seeing as I can't find the thread on the forum now, but I believe there was a conversation where someone was having trouble dynamically creating [bpatcher]s from within javascript. There was mention of newdefault() vs newobject() vs patcher.message("script","newobject",...) but I can't remember what the exact issues were or their solutions. You should probably just ignore all that until any problems arise.
      In regards to [posit] I created a basic [js] version a while back which you can find here. You might find it useful. Basically if you already know the scripting name of an object you can find it in javascript by doing something like this:
      var obj_pos = this.patcher.getnamed(someScriptingName).rect;
      where the obj_pos variable will be an array of the position as it would appear in the object inspector.
      If you have any other questions or you want me to take a look at the patch/code you have so far then post it here. Any presents you can save until my birthday in April!
    • Jan 20 2010 | 7:50 pm
      I didn't write it on this forum, but I did have some trouble creating bpatchers, though I didn't really follow it down.
      The issue is that the identify patch contained in it isn't set with an argument to the bpatcher box, but with a parameter; yet, trying to set that parameter after the bpatcher is created doesn't seem to bring that patch into the patcher.
      YMMV; I experimented and went a different way.
    • Jan 20 2010 | 8:18 pm
      creating bpatchers with a patch inside is possible if the associated file is in the same folder.
      [script newobject bpatcher @name getsize.maxpat]
      works fine.
    • Feb 01 2010 | 8:56 am
      -->But I found an external I've never used called [posit], in the Jash library which can query x-y coordinates of objects with scripting names. Does anyone know how to do this without externals?
      [pattr] can bind to an object's attributes as well as its state. Check the Help file to see the syntax. In this case you can bind to the object's patching_rect or presentation_rect, so the top/left/width/height values will be shown in real-time in the patch. Running them though some number boxes and back into a message "patching_rect $1 $2 $3 $4" and to the object, you can store object positions (as pattrstorage slots) after moving the objects with the mouse. You will need a "set" at the correct place to avoid a stack overflow though :)
      best part about this is to then interpolate between your stored slots, which moves and resizes everything!