Forums > Javascript

How to know the name of a mxj or a bpatcher ?


f.e
April 30, 2009 | 12:30 pm

Hello,

How to know the name of a mxj or a bpatcher ?

For js, objectsInPatcher[count] = b.js.jsarguments[0];
is ok, but i have no clues for mxjs and bpatchers…

Any help ?

fe.


April 30, 2009 | 1:15 pm

To find which file is loaded into a [bpatcher] you can use the js code included below. It will find any attribute of a named object if you send it the message "getattr ". For [bpatcher] the attribue is "name". I hope this helps.

lh

// getattr.js
function getattr(varname, attr)
{
myobj = this.patcher.getnamed(varname);
outlet (0, myobj.getattr(attr));
}
// EOF



f.e
May 4, 2009 | 9:42 am

Thanks a lot !



f.e
May 4, 2009 | 10:33 am

By the way, your method is good but doesn’t help to find if it’s a patcher saved as an abstraction, a embedded patcher like [p stuff], or a bpatcher. Any ways to know ?

And still no clue to get the name of mxj’s ?

best wishes

f.e


May 4, 2009 | 11:04 am

A quick yet not-particularly-clever way of testing if its a [patcher] is to [sprintf %s.maxpat] the output to an [absolutepath] object. If its an abstraction or [bpatcher] it should show you the destination. However this is also true if you name your [patcher] the same as a file in your search path.

To test for abstraction vs. [bpatcher] you could try myobj.getattr() and then test for an attribute that only the [bpatcher] has, like "offset" or "clickthrough", I haven’t tested this though so no promises it will work.

I’ll look into this a bit closer when I finish work this evening.

lh



f.e
May 4, 2009 | 11:08 am

I’ve just tried getattr("offset") and other things but it doesn’t work at all, for unknown reasons (it should work, indeed). For example "offset" always returns 1 for everything, patchers, bpatchers… while "enablehscroll" always returns "null"…

f.e


May 4, 2009 | 11:13 am

That is odd. I’ve had trouble with getattr() before (see link below) but assumed it was me doing something wrong. What’s weirder is that it finds "name" but not some of the other attributes. It’s quite annoying that [patcher], [bpatcher] and abstractions return "patcher" as the maxclass but thats just the way it is I guess.

lh

http://www.cycling74.com/forums/index.php?t=msg&th=38427&start=0&rid=7622&S=1781d2bc03152438b301375aaeb8adc0


May 8, 2009 | 3:30 pm

Right I’ve been trying to figure out ways of telling apart [bpatcher]s, [patcher]s and abstractions in javascript. So far no solid way to do this but there is an untidy work-around.

First I tried the obj.getattr("ignoreclick") which doesn’t work (anyone know why?).

Next I tried obj.understands("ignoreclick") which works when the [bpatcher] is empty but not when there is a subpatch loaded into it, which sort of makes sense as the subpatch could understand that particular message.

Lastly I tested the height of the object and if it’s greater than my regular object size of 20 then assume it is a [bpatcher], not great but does the job in most cases.

if ((obj.rect[3]-obj.rect[1] > 20) && (obj.maxclass == "patcher"))
{ execute this code }

lh


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