How to pass Argument(s) to newdefault to instantiate bpatcher

Duggle ...'s icon

var p = this.patcher
var maxObj = p.newdefault(100,100,"bpatcher","CCknob1.maxpat");
This puts the bpatcher from file into the patch but I need to set the arguments like I would if I was placing the bpatcher manually. In this case I have the Argument(s) field in the bpatcher Inspector is set to :
"@name Vol @CC 7"
How would I code to include arguments?
Thanks for any hints.

tyler mazaika's icon

I think you can just put the arguments directly after the name of the "CCknob1.maxpat", no?

In my code snippets I have something for doing variable/unknown-length arguments list like this:

var instantiation_arguments = [100, 100, "bpatcher", "CCknob1.maxpat", "@name", "Vol", "@CC", 7]
var new_obj = p.newdefault.apply(p, instantiation_arguments)
new_obj.varname = varname // need to specify this if you want it

Duggle ...'s icon

Thanks, but unfortunately I continued to get errors, in this case
bpatcher: bpatcher: error loading patcher Vol
even after changing the "@name" to "@handle" and respective changes in the bpatcher.
This had been using the @ attribute method of args (a list coming out of the right output patcherargs object inside my bpatcher CCknob1.maxpat, called "attribute arguments" in the outlet assist tooltip)


Working now: I changed this to use the left output of patcherargs (called "normal arguments" in the tooltip)
These are ordered arguments without @ labels, commas, or quotes, when used manually from the bpatcher inspector. So the working code is thus:
var maxObj = p.newdefault(100,100,"bpatcher","CCknob1a.maxpat","@args", "Vol", 7 );
Wow, no documentation (that I could absorb) and no tutorials could I find on this, took a while to crack...