get scripting name hierarchy of nested bpatchers

    Dec 11 2013 | 1:35 pm
    Dear forum,
    I am aware of and have many times used this javascript from Luke Hall (thanks!):
    function bang() { if({ outlet(0,; } }
    to get the scripting name of a bpatcher from inside itself.
    I'm wondering if it's possible to use a similar method to find out the scripting names of all of the parent bpatchers when dealing with nested bpatchers, each with their own scripting name.
    I'm looking for something that will spit out the scripting names in hierarchical order (up or down) so that I can then convert it to this:
    where each xxx_level is the scripting name of the bpatcher (from topmost to the current one).
    Is it possible with a bit of js code like that above or any other similar (seemingly) simple method?
    This is for a large project that includes the ability to dynamically create bpatchers within bpatchers within bpatchers etc and I want to be able to turn any arbitrary nested child bpatcher's active state to pattrstorage on/off which is only possible when using the syntax:
    "active top_level::middle_level::bottom_level $1"
    Thank you for your help/time!

    • May 12 2014 | 5:16 pm
      Bump +1
    • May 13 2014 | 12:11 am
      You can iterate through the hierarchy by testing or something, maybe something like this:
      function bang() { outlet(0, getPath(this.patcher,; }
      function getPath(p, path) { if( { path = + "::" + path; return getPath(p.parentpatcher, path) } else return path }
    • May 13 2014 | 12:44 am
      Hi Ben,
      Thank you for your reply. And thanks DHJDHJDHJ for the bump.
      Ben, your javascript returns a syntax error. I've tried but I'm not able to decipher how to fix it.
      When you have a moment, could you please have another look at it or anyone else who is able. I'm sure it's something very simple.
      Thank you!
    • May 13 2014 | 1:24 am
      Sounds like you have it in a top patcher. You can add a check to see if the patcher is a top patcher:
      function bang()
      	if(this.patcher.parentpatcher) // make sure the current patcher is not a top level patcher
      		outlet(0, getPath(this.patcher,;
      function getPath(p, path)
      			path = + "::" + path;
      			return getPath(p.parentpatcher, path)
      	else return path
    • May 13 2014 | 2:09 am
      Hi Ben,
      Thanks for the updated js but the bpatcher where the js is located is three levels (bpatchers) deep, it's not the top level patcher.
      When instantiating the bpatcher the js syntax error in max window reads:
      Javascript SyntaxError: illegal character, line 13 source line: path = + "::" + path;
      I also get: "js: no function bang" when sending the js a bang.
      Out of interest, when I try loading the same js into a top level patcher, it also returns the exact same errors (using the new js you just posted).
      Thanks heaps for your help.
    • May 13 2014 | 2:13 am
      Hi Joe,
      No idea what is going on there. if there is no function bang(), then it doesn't sounds like the script was pasted in correctly. There is definitely a function called bang :)
    • May 13 2014 | 2:38 am
      Hi Ben,
      Yeah. It's very strange. Definitely pasted in correctly, appears identically.. Definitely not working though. Other js I have with function bang are currently working so will compare them later today when I get another chance.
    • May 13 2014 | 7:01 am
      Thanks so much Ben. Your javascript works a treat for my purposes and you've been super helpful.
      FYI, the problem I was having with the pasted javascript had to do with the inverted commas around the colons ("::"). They must have been formatted strangely from the forum, the looked to be in italics (or similar) and so I replaced the ones in the js by typing them in manually. The freshly typed inverted commas solved the problem I was having and all works as it should now.