Forums > Javascript

getting presentation rectangle of object in JS

April 18, 2011 | 6:50 pm

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


April 18, 2011 | 9:52 pm

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"));
}

April 18, 2011 | 10:14 pm

Thanks once again Luke!


April 18, 2011 | 11:24 pm

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:

– Pasted Max Patch, click to expand. –

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

Thanks.


April 19, 2011 | 1:22 am

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?


April 19, 2011 | 2:47 am

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.


April 19, 2011 | 3:26 am

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.


Viewing 7 posts - 1 through 7 (of 7 total)