getting presentation rectangle of object in JS

elmiller's icon

Hi,

I know using this.patcher.box.rect is a method for getting the patching rectangle of an object in JS, but is there a way to do the same for getting the presentation rectangle? I only saw one old post asking this with no solution.

Thanks,
Eric

Luke Hall's icon

You can use getattr(), here's an example of how to find the co-ordinates of a named object in a patcher:

function bang() {
    outlet(0,this.patcher.getnamed("someobj").getattr("presentation_rect"));
}
elmiller's icon

Thanks once again Luke!

elmiller's icon

Luke, this works great except when I am calling the bpatcher or subpatcher the js object is contained in. I am getting a "jsobject 0" message. Am I doing something stupid?

example:

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

-----------getparentattr.js-----------
function getattr(varname, attr)
{
myobj = this.patcher.parentpatcher.getnamed(varname);
outlet (0, myobj.getattr(attr));
}
------------------------------------

Thanks.

Luke Hall's icon

Calling your function "getattr" and calling the getattr() method inside that function is probably not the best idea to start with. Your patch works on the [toggle] but not on the [patcher] object when tested. I think this might be a UI object vs non-UI object issue. I've never really got to the bottom of what works and what doesn't with getattr() but maybe I'm missing something simple, perhaps to do with the "sendbox" needed if you send this message with an object box outside of javascript?

elmiller's icon

I think you're right about UI vs non. I thought it had something to do with hierarchy, but once I tried it on non-UI objects other than the subpatcher I got the same message. I'll try looking into the "sendbox" thing. Thanks again for your time.

elmiller's icon

Just an update: a bpatcher works if it is not the one containing the js obect, but if it does contain the js object, I get the "jsobject 0" message. So I guess it's not strictly a UI vs non-UI issue.