getting presentation rectangle of object in JS

Apr 18, 2011 at 6:50pm

getting presentation rectangle of object in JS

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

#56409
Apr 18, 2011 at 9:52pm

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"));
}
#202294
Apr 18, 2011 at 10:14pm

Thanks once again Luke!

#202295
Apr 18, 2011 at 11:24pm

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.

#202296
Apr 19, 2011 at 1:22am

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?

#202297
Apr 19, 2011 at 2:47am

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.

#202298
Apr 19, 2011 at 3:26am

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.

#202299

You must be logged in to reply to this topic.