Max patch instrospection

    Apr 23 2019 | 1:05 am
    I'm curious about introspection in Max patches. Is there a way to query patches to receive information on the current objects, or query max to get info on current patches, etc? I'm specifically curious to do this while patching, not on traversing a saved .maxpat file with another language.
    I'm thinking of something along the lines of a message:
    "; max listObjects"
    to get a list of all objects in patch, or in JS / NodeJS:
    this.patcher.listObjects() Max.listPatches()
    Does anyone know of any resources or methods? If this can be done in NodeJS or js, that works well. Just looking to stay inside of Max

    • Apr 23 2019 | 7:11 am
      This javascript comes from this forum, but not sure which thread: /* August 2013 based on 'patchdescribe.maxpat' which is a simple example of iterating through all objects in a patch (included in the Max examples). */
      // set up inlets/outlets/assist strings
      outlets = 2;
      setoutletassist(1,"clear message for coll");
      setoutletassist(0," / maxclass ");
      function bang()
      function iterfun(b)
      	outlet(0, + " " + b.maxclass );
      	return true;	
      iterfun.local=1; // keep private
      Name it jpatchmap.js And here is the example patch for it:
      It will iterate through any subpatchers that are in the patch, as illustrated in the example
    • Apr 23 2019 | 3:12 pm
      This is beautiful! Thank you so much for sharing!
      Before I go about building something out from this, it looks like this stuff is designed to be formatted as a dictionary / object. Does any code exist to convert this to JSON?
    • Apr 23 2019 | 7:39 pm
      i dont remember offhand now, but listing all objects in a patcher can be achieved by some key combination and clicking in the patcher window since ever. this is even less work than the other option, using the file menu.
    • Apr 24 2019 | 2:08 am
      I think you'd need to hand-code it; have a look at the "Javascript in Max" pdf that should come with Max, especially the Patcher Object section. I think you'd probably need to iterate through the patcher, place object names in an array, then stringify and format the string. The stringification is helped using JSON.stringify(). an example: function bang() { var first = [1, 2]; var second = [3, 4]; var nested = [first, second]; post(first); post(); post(second); post(); post(nested); post(); post(JSON.stringify(nested)); post(); } But I haven't done anything like this in years and I'm no js expert, so there might be a way more straightforward way to get info into a dict