newobject() arguments for bpatcher

Sophia's icon

Hi,

As my first foray into JavaScript within Max, I'm trying to do automate the creation of a series of bpatchers, similar to the example in the "JavaScript Scripting" tutorial.

I have to admit, I'm having some trouble figuring out the order of arguments for newobject() from looking at the documentation. First I tried this:

numbpatchers = a;
for(k=0;k
{
thebpatchers[k] = this.patcher.newobject("bpatcher", "FloatingButtons.maxpat", k*100, 0, (k+1)*100, this.patcher.wind.size[1]);
}

Then this:

numbpatchers = a;
for(k=0;k
{
thebpatchers[k] = this.patcher.newdefault(0, 0, "bpatcher");
thebpatchers[k].replace("FloatingButtons.maxpat");
thebpatchers[k].rect(k*100, 0, (k+1)*100, this.patcher.wind.size[1]);
}

But neither seem to work as desired. All I want to do is set the rectangle (actually in presentation, but I'm just trying to get it running at this point) and file. I'm sure this is very simple, I just can't seem to find many examples of scripts that create new objects other than the one in the tutorial that uses newdefault() and doesn't set any parameters.

Thanks,
Zach

Luke Hall's icon

Is FloatingButtons.maxpat in your search path? If not you will have to use the full file path to get this to work. The second method where you call replace() works for me.

lh

Sophia's icon

It is in the search path. The second method loads the file, but the rectangle is not correct. It should create 100 pixel wide vertical strips that are the same height as the window. As noted, I'd also like it to set the presentation rectangle if you could point me to that function.

Please correct me if I'm wrong, but it seems I should be able to create the object and set all of these parameters by just calling newobject(). But how do I find out the correct argument order for bpatcher, or any object for that matter?

Thanks,
Zach

Sophia's icon

Any ideas?

Thanks,
Zach

woodslanding's icon

Did you ever get this figured out?

Julien Bayle's icon

interested too
digging that actually (I mean now)

Hugobox's icon

This works fine for me:

function createBpatcher(file,varname,args)
{
offset = this.patcher.box.rect;
object = this.patcher.parentpatcher.newdefault(offset[2],offset[1],
"bpatcher",
"@name", file,
"@patching_rect", (offset[2]+5), offset[1], "128", "128",
"@presentation_rect", (offset[2]+5), offset[1], "128", "128",
"@border", "0",
"@varname", varname,
"@args", args,
"@orderfront", "1",
"@hint", varname,
"@embed", "0",
"@presentation", "0");
}

Julien Bayle's icon

reminds me overriding of class in other worlds ;-)
thanks for your post, it helps me right now :)

Julien Bayle's icon

this.patcher.newdefault(0,0,"bpatcher","@name", path);
creates a patcher without name, but no complains in max window

any ideas?
it sounds very weird :-/

Julien Bayle's icon

I meant, it doesn't create a bpatcher and I don't know why ?!
(max6)

Julien Bayle's icon

WEIRD.
I just quit, reload. it is ok.