How to set the patcher window size with JS

startec's icon

Does anyone know how to set the size of the presentation window of a patcher itself with javascript? I am interested in doing this because I want the presentation (and patching) window size to depend on how many slider I make with a javscript window. On all objects there is the presentation_rect and patching_rect property names but those don't seem to exist for an actual patcher window. Thanks for any help.

Lee's icon

do you want to adjust the overall window size??

this.patcher.window( "size", x, y, x + w, y + h )
this.patcher.window( "exec" );

??

startec's icon

Hi Lee,
Thanks for your answer, this is exactly what I needed to know. If you don't mind though, can you help me understand how you did that? In the documentation I do not see anything for the "size" attribute of this.patcher.window and I do not see anything for "exec" either. It seems like a new way to send messages to objects

In fact, I really don't see any documentation for this.patcher.window at all, so I don't get how to message it.

Also, now that I know how to change the size / placement of the patcher window with js, could you help me change the size and placement of the patcher window when it is in presentation mode (if these can be changed individually)?

One issue is that, in the patcher inspector, certain properties are just not listed.

var mess = this.patcher.getnamed("message");
var b = mess.getattr("bgcolor");
post(b);

will print the background color of a message box, but the bgcolor attribute doesn't even exist for this.patcher.window

Further, trying to get an attribute that is listed for a patcher object, does not work. i.e.

var c = this.patcher.window.getattr("openrect");
post(c);

Thank you very, very much.

Lee's icon

Hi sure - alot of the documentation for thispatcher is in the thispatcher object. if you ALT-click on a thispatcher object or navigate to it in help menu, you'll see a section at the bottom "double-click to see more features" - this contains lots of other info - for example, the first subpatch shows you all the window commands you can send to set flags, position etc.

the window position is for the window - it cannot be set (as far as I know) separately for presentation and patching...

i find this part of the doc probably most confusing of all - windows, patchers and the cross-over into js - takes alot of experimentation and playing around...

not really had occasion to use getattr so don't really know much about it.... might have a play...

Simon O'Rorke's icon

I know this is an old thread. But I was drawn to it and found it useful. And I can now provide some additional information. The following is based on Max 8, which was released subsequent to the previous posts in this thread. Not having used previous versions, my guess is that some or all of the following is new since those previous posts.

Startec wrote:

I really don't see any documentation for this.patcher.window at all, so I don't get how to message it.

I have found one passage of documentation that, though it does not discuss patcher.window specifically, is relevant. It's brief, so I shall quote it in full. In the "The Patcher Object" documentation page in Max Reference, it says:

Patcher Methods Overview

Any message to a patcher that you can send in Max (via the thispatcher object) you can send in Javascript in js.

Examples:

p = this.patcher;
p.fullscreen(1); // makes the patcher take up the whole screen
p.dirty(); // make an editable patcher dirty

That reference page goes on to document several properties that are specific to the Javascript Patcher object and do not completely replicate the messages that can be sent to the Max thispatcher object. In particular, there's a Wind property that overlaps the window message in functionality: see the The Wind Object documentation page in Max Reference. So to set a window's position and size, an alternative to

this.patcher.window("size", x, y, x + w, y + h);
this.patcher.window("exec");

is

this.patcher.wind.location = [x, y, x + w,  y + h];

(Note the improved term location compared with the misnomer size. Wind does have a size property too. But it's used strictly for getting or setting a window's size, without reporting or changing the window's location/position, as specified by its top left corner.)

But I cannot find a way to maximise a window using Wind. With window, it's

this.patcher.window("zoom", 1);
this.patcher.window("exec"); 

Conversely, I cannot find a way to get a window's position and size with window. With Wind, it's

location1 = this.patcher.wind.location;
outlet(0, [location1[0], location1[1], location1[2], location1[3]]);