Change default bpatcher presentation dimensions of 128 square
Hello
I've been wracking my brain for hours now and cannot find how to limit the size of my bpatcher when I refer to it in a new object.
I followed this: https://www.youtube.com/watch?v=K5kcNxjK6Os&t=301s
to create essentially a package in my Packages path in max, and set it up so that when I open a max patcher, n for new object and type mytest it autocompletes, and when I hit return I see the bpatcher pane instead of just an object box with the name in. Fine.
But the bpatcher pane that results is 128 x 128px. Once it is deployed, I can modify this, but I want it to drop with a different dimension as I will be pulling a lot of these bpatchers in all my instrumentation as I build out and I'd like to slot them in with the target dimension for the design.
I've tried using @presentation_rect in the objectmappings.txt file in the init subdir of my package (ignored), a whole host of script, prepend and other such messages to the thispatcher object in the sub patcher file, but none of those recommended on other posts work for me.
Apparently this.patcher.box.rect works for JSUI objects but I don't programme JS and have none included in my work and don't know how to use that reference in a normal patch.
How can I control the bpatcher presentation pane dimensions prior to when the object is dropped into my patcher?
a different size for newly created objects can be achieved best by using ->prototypes.
to be exact, in a bpatcher prototype you can have both, the patcher file and the size already included.
other than that, why do you need to create it with the correct size already? it should normally not cause major graphics glitches to do it after creation.

Roman thanks for the response.
I have a patcher in a package so I can just type the first few letters of the patcher and it will autocomplete and I hit return to get my open-in-presentation bpatcher drop with the UI I designed.
The UI consists of a smaller summary area with buttons to open (etc) the full UI where I can configure the component. When I drop currently, the UI I see is 128 pixels square but the summary area in the presentation view of the subpatcher is only 70x70 (and -20 -20 offset).
The offset I nailed in the objectmappings.txt file but the dimensions of the bpatcher that drops via the package I cannot seem to find the right combo of config to make it drop with a 70x70 view port into my subpatcher. As this component is an EQ, I'm going to use it loads so want it to drop in and work with my designs without me having to modify it.
This is the objectsmappings.txt file in my package:max objectfile mytest mytest;
max definesubstitution mytest bpatcher @name mytest.maxpat @offset -20 -20
Is it possible to add @size to a thispatcher in this file in some way?
Or maybe inside the patcher I pull in a bpatcher a
script sendbox #thispatcher 70 70
message or similar where #thispatcher is the thispatcher object the message object is wired to?
it is tempting to try to set the [thispatcher] of the motherpatcher from inside the bpatcher, but even if it seems to work i would recommend against it. it is too dangerous to rely on initialisation from inside bpatchers, because they tend to think they would be someone special and do not obeye the simplest rules.
so you´re preferred way to call new instance is to type "bpatcher myeq..." into an object box?
until someone else has a perfect solution for exactly that, i think you could meanwhile try some alternatives.
f.e. it is not difficult to use thispatcher-scripting to create your bpatcher incl. filename and size, and then you can create new instances by a single click on a button (or a keyboard command of your choice).
or even haven new instances created using automatic positioning and autoconnected them to other objects.
oldstyle script-create a bpatcher:

Roman thanks for the insight.
I've struggled with this notion now for a week, every night looking through options, objects, package creation, bpatcher/thispatcher, js and I've agog as to why I can use packaging to easily set the offset of a bpatcher on creation, but not change the default 128-square pixel window it creates - looks like a massive oversight and something that should be easy to fix in the underlying codebase.
Cheers!
You could use: "@patching_rect 10 10 70 70 @presentation 1 @presentation_rect 10 10 70 70" and so on in the mapping-file? Or do you want to change only size and not the position?
Then use JS. A good example is [node.debug] look inside the bpatcher and see

a js is used to resize at patcher load. You probably need to extend this script to make it universal and also set the presentation state and size if needed.
10107070 points to @11OLSEN!
Adding those attributes to the objectmappings.txt file fixed the result every time an instance was dropped, but did work. The js resize version worked like a dream! Thanks so much. I changed down the deferlow to a defer and it worked a little better, but both give the perfect end result.
Thanks again.
@DIATOM I have tried both of those solutions and still cannot get them to work. Can you share objectmappings.txt file and how you set up the js file?
Hello @WIL yes I'm delighted to say I got it working:
I have created a pkg in my path. This allows me to hit 'n' and type mytest pkg and get auto-complete and without me having to precede the name with `bpatcher` or whatever and with the aim of typing the name but hitting return and getting a UI component not an object box I then have to use the context menu for to convert to bpatcher or a prototype call.
In ~/Documents/Max 8/Packages/mypkg:
.
|-- help
|-- init
| `-- objectmappings.txt
`-- patchers
|-- mytest.maxpat
`-- resize_this_patcher.js
In objectmappings.txt:
max objectfile mytest mytest;
max definesubstitution mytest bpatcher @name mytest.maxpat @offset -20. -20.
This means my subpatcher's presentation mode UI I have starting on pixel 20x20 making for nicer subpatching experience. I want it dropping in this manner so it will reveal its UI through the bpatcher pane offset 20x20 to where I want the top left corner of my UI component when it's dropped into the mother patcher.
In resize_this_patcher.js:
function resize() {
this.patcher.box.varname = "bp_" + Math.random()*10000;
this.patcher.parentpatcher.message("script", "sendbox", this.patcher.box.varname, "patching_size", 70, 70);
this.patcher.box.varname = "";
}
This means the bottom right hand corner of the UI component that drops on the mothercanvas is 70x70 away from the top left as defined in the objectmappings.txt file.
In your subpatcher floating somewhere:

I didn't use deferlow as 11Olsen did above as I experimented: deferlow dropped a 128 square bpatcher UI in immediately and about an th of a second later, resized it when the scheduler hit/interpreted the js script read in presumably when the package was dropped into the mothercanvas hence the slight delay. I would think for a complex subpatcher (eg a fully fledged sampler UI), the delay before rendering may increase, unsure atm till I build something like that. The defer instead caused an immediate resize due to the way defer works instead of deferlow.
Restart Max so it picks up the package changes.
Open the mothercanvas and hit n. Type mytest and hit return and the 70x70 window in your subpatcher should drop immediately.
Let me know how you get on!
Hi DAITOM- nah I can't get it working.
Followed your steps
I downloaded Federicos file cool.patcher.maxpat
added resize_this_patcher.js to his patch
it opens but error calling the js
I have no idea!






However - here is a variation
-using Federico's example:
I made a 'clippings' folder and you can create a blank patch and drag the patch from the clippings folder to the canvas. I like this better. Works like BEAP or VCV rack. Help file works as well.
I removed all the js.
If you can update this with proper js - then - best of both worlds!
Thanks DAITOM!
The js error is because the file needs to be in the same directory as the patcher that calls it, and the files need to be in a patcher subdirectory along with the package subdirectory set that I included in order to map into the package requirements.
Thanks. That worked.
The problem was:
I put it in Documents/Max 8/mypackage
Needed to put in Documents/Max 8/packages/mypackage
Very cool! Now both work:
n then name of patch
~or
drag from clippings folder
Just as an aside, and for maximum transparency as to how green I obviously still am, if you have your mother patcher in presentation mode, dropping your package will not cause the js to run, because it is configured to
this.patcher.parentpatcher.message("script", "sendbox", this.patcher.box.varname, "patching_size", 70, 70);
Adding this line to the JS means it also works when in presentation mode - which my mother patch now defaults to loading in for performance reasons.
this.patcher.parentpatcher.message("script", "sendbox", this.patcher.box.varname, "presentation_size", 70, 70);
I do note that in the normal inspector windows, the references are presentation_rect
and patching_rect
, not presentation_size
and patching_size
. Perhaps there is more on this buried in the JS docs.
Cross-posting in this post.