Bpatcher and rect
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);
in case anyone is still looking:
bpatcher.box.rect will get you this.
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);
wait, really? You can't just set the presentation_rect attribute?! wtf?
You can also do something like this:
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()
}
Mattijs, thank you! That is very handy and very crafty.
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.
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")}
Hi @Mattijs,
This is great, thank you!