Bpatcher and rect

Baptiste Manson's icon

Hi there,

I need some help getting both the presentation rectangle and the patching rectangle attributes of a bpatcher. I know this topic has been addressed already here over and over again, but it didn't work for me.

If I have a bpatcher called "bpatcher", then in js:
bpatcher = this.patcher.getnamed("bpatcher");
bpatcher.getattr("presentation_rect"); //is null
bpatcher.getattr("rect") //is set, seems absolute on screen.
bpatcher.rect //is set, seems relative to the current window.

How can I get both the presentation and the patching rectangle of a bpatcher?

Thanks for your time,
PS: I was able to set those attributes, via
this.patcher.message("script", "sendbox", p.varname, "presentation_rect",0,0,100,100);

DRKOSS's icon

in case anyone is still looking:

bpatcher.box.rect will get you this.

DRKOSS's icon

or if you need presentation_rect to change:

this.patcher.message("script","sendbox","bpatcher","presentation",0);
this.patcher.getnamed("test").subpatcher().box.rect=[0,0,600,100];
this.patcher.message("script","sendbox","bpatcher","presentation",1);

AudioMatt's icon

wait, really? You can't just set the presentation_rect attribute?! wtf?

estevancarlos's icon

You can also do something like this:

Max Patch
Copy patch and select New From Clipboard in Max.

Mattijs Kneppers's icon

I managed to get and set presentation_rect for a bpatcher with a MaxobjListener:

if (obj.maxclass == "patcher" && obj.getattr("presentation_rect") == null) { // bpatchers return null for presentation_rect, as opposed to normal patchers
var l = new MaxobjListener(obj, "presentation_rect", null)
var r = l.getvalue()
}

tyler mazaika's icon

Mattijs, thank you! That is very handy and very crafty.

Simon O'Rorke's icon

In my case, Mattijs's solution also worked to get the bpatcher's patching rectangle ("patching_rect"), when the bpatcher's Maxobj.rect returned an incorrect value (with left and top correct but right and bottom wrong). Thanks! I don't know why Maxobj.rect did not work. It presumably somehow has something to do with the fact that I had added the bpatcher programmatically in Javascript.

Mattijs Kneppers's icon

Quick update: there is also another method to get the bpatcher presentation rectangle, getboxattr:

if (obj.maxclass == "patcher" && obj.getattr("presentation_rect") == null && obj.getattr("presentation")) { // bpatchers return null for presentation_rect, as opposed to normal patchers
    var r = obj.getboxattr("presentation_rect")}
Martin.Jirsak's icon

Hi @Mattijs,

This is great, thank you!