patcher.newobject() syntax?
I assumed that this would already have been asked in this forum, but I couldn't find a previous post that explained the syntax of the patcher.newobject() method.
The documentation lists the syntax as:
newobject(classname,params)
and gives the example of:
a = patcher.newobject("toggle",122,90,15,0);
What does the 122,90,15,0 refer to? Are there always just four parameter arguments for any object you create, or does it vary depending on the object type? If it varies for each object type, then where can I find a list or pattern of parameters for each object type?
What I'm trying to do is create objects using js, and keep their MaxObj objects stored in variables so I can do things to them later. I need to create bpatchers (among other things) which are visible in presentation mode, set their presentation mode rects, and set the file that they are loading. I've seen the this.patcher.message() way of creating objects and setting their parameters, but I don't want to use that because it doesn't return a MaxObj object.
I can't find anything in the documentation, examples, or in this forum that will give me a hint on how to do that. Any suggestions?
Is the javascript forum completely dead, or is this question currently not answerable?
Seems odd to me to tout a great new feature in the documentation (newobject method) and then give no instructions on how to use it. Especially when it's really not obvious how to use it... Can any c74 people give me a hint?
Ok, well I've done some digging in the forums and the documentation, and I've also done some trial and error, and for the posterity of future javascripters, here's what I've found:
First of all, newobject() is not a new feature in max 5 (I thought it was). I guess I never used it because it wasn't terribly well documented in max 4 either.
Anyway, here is the way I've found to script a bpatcher, retain the maxobj object associated with it in a variable, change its size in patching mode, change its size in presentation mode, and enable/disable its visibility in presentation mode:
function bang()
{
var myobj = patcher.newobject("bpatcher"); //create new bpatcher
myobj.rect = [300,300,400,400]; //set size and location of bpatcher in patching mode
myobj.presentation(1); //add this object to presentation mode
myobj.presentation_rect(300,300,400,600); //set size and location of bpatcher in presentation mode
myobj.replace("bpatcher_test.maxpat"); //load a patch into the bpatcher
myobj.offset(100,150); //set the offset of the view into bpatcher
}
I guess I was under the impression that the arguments to the newobject() function would allow me to set a lot of these parameters without having to send individual messages to the bpatcher. At this point, I have absolutely no idea what the arguments to the newobject() method do. For some objects, they appear to be the rect of the object, for others they determine the size of the object, for others... who knows? No matter what I put in for the args of patcher.newobject("bpatcher",arg,arg,arg,...), I always end up with a 128x128 bpatcher at 0,0.
*shrug* I guess you have to work with what you're given.
The way you are doing it is fine, but if you are using Max 5, you can just use the 'newdefault' method and set @attribute values.
The @attribute stuff isn't really documented at the moment, but something like this will work:
function bang()
{
var myobj = patcher.newdefault(300, 400, "bpatcher", "@patching_rect", 300, 300, 400, 400, "@presentation", 1, "@presentation_rect", 300, 300, 400, 600, "@name", "bpatcher_test.maxpat", "@offset", 100, 150);
}
On Oct 15, 2008, at 1:25 PM, Scott wrote:
> At this point, I have absolutely no idea what the arguments to the
> newobject() method do. For some objects, they appear to be the rect
> of the object, for others they determine the size of the object, for
> others... who knows? No matter what I put in for the args of
> patcher.newobject("bpatcher",arg,arg,arg,...), I always end up with
> a 128x128 bpatcher at 0,0.
Sorry these arguments aren't documented nor will it ever be by c74,
but it can be reverse engineered based on the save as text in Max 4.
newobject is the legacy Max 4 scripting format. There have been
threads on this in the past if you dig deeper in the archives. With
Max 5, however, follow Ben's advice and use the newdefault() method
with attribute arguments.
-Joshua
I am trying to change the presentation rectangle of a bpatcher object through javascript after it has already been created. Attempting to use the "presentation_rect" method that swieser1 provided yields a "patcher: doesn't understand 'presentation_rect'" error in the Max main window.
I would love to understand what is going on. Is any of this documented anywhere?
drrr,
the presentation_rect method worked for me in the example code above. maybe you're not using it correctly. copy and paste your code into this forum so we can have a look at it.
the one thing that's tipping me off is that the error message says "patcher: doesn't understand..." instead of "bpatcher: doesn't understand..."
Are you trying to use the presentation_rect method on the bpatcher object, or on the patcher object?
I actually just took the code you provided and added an additional statement:
function bang()
{
var myobj = patcher.newobject("bpatcher"); //create new bpatcher
myobj.rect = [300,300,400,400]; //set size and location of bpatcher in patching mode
myobj.presentation(1); //add this object to presentation mode
myobj.presentation_rect(300,300,400,600); //set size and location of bpatcher in presentation mode
myobj.replace("bpatcher_test.maxpat"); //load a patch into the bpatcher
myobj.offset(100,150); //set the offset of the view into bpatcher
myobj.presentation_rect(100,100,200,200);
}
The result is the aforementioned error message and a bpatcher with a presentation_rect of "300, 300, 400, 600." However, if I take out the replace() and offset() calls, I can call presentation_rect() as many times as I wish and it works. Once replace() is called, however, this ceases to be the case.
I also attempted to use presentation_rect with a bpatcher created through newdefault(), and that just doesn't work at all. Code:
function bang()
{
var myobj = patcher.newdefault(300, 400, "bpatcher", "@patching_rect", 300, 300, 400, 400, "@presentation", 1, "@presentation_rect", 300, 300, 400, 600, "@name", "test.maxpat", "@offset", 100, 150);
myobj.presentation_rect(100,100,200,200);
}
Error:
"js: test.js: Javascript TypeError: myobj.presentation_rect is not a function, line 8"
How does one re-size a bpatcher that has already been given a subpatch to display?
Hmm, I haven't tried adding the offset and replace functions in there yet... This seems like it could be a legitimate problem. Anyone at c74 have any ideas why this might be happening?
I can confirm that this behavior is happening for me too.
I've sent a bug report to support@cycling74.com
We'll see if they have any answers.
> these arguments aren't documented nor will it ever be by c74,
> but it can be reverse engineered based on the save as text in
> Max 4.
now that is some valuable information! it seems a weird policy to have javascript available in max, but no tutorials or reference items going into details about certain commands there. Since i am answering this 1 1/2 years after the post quoted above i wonder if now - for mac 4.63 nevertheless - there is a kind of tutorial or reference document about the use of the newobject(), especially regarding the arguments available for standard max objects and the right order of arguments as well.
i appreciate ANY helpful hint regarding this, thank you very much in advance!
jrp
jayrope,
This thread is only about a month old...
Anyway, see jkc's post in this thread for your answer:
"Sorry these arguments aren't documented nor will it ever be by c74,
but it can be reverse engineered based on the save as text in Max 4.
newobject is the legacy Max 4 scripting format. There have been
threads on this in the past if you dig deeper in the archives. With
Max 5, however, follow Ben's advice and use the newdefault() method
with attribute arguments."
So, if you look at the text version of your max 4 patch, then you can use the arguments that appear there in your js script.
You must have gotten me wrong, look, i had quoted the same piece of text.
Following that quote i was meaning to ask if someone or Cycling74 themselves have taken the effort of doing a list of available arguments for scripted patcher objects using newobject() in the meantime.
In fact i'm already now in the process of "reverse engineering" available arguments, for max 4.63.
It's fun :)
Even dynamically produced cabling between objects can be completely hidden in the first place.
As soon as i have a list of things i'll post them.
jrp
Sorry, didn't see that you quoted jkc's post already.
In any event, the words are pretty clear: c74 has not and is not ever going to document the arguments to the newobject() function.
At this point, it may not even be worth the trouble for you to document it, since the newobject() function is only marginally useful in 4.6, and completely useless in max 5 (since we can use the newdefault() function now).
very friendly comment, thank you.
i can momentarily not afford to upgrade and am just looking for help.
anyone else maybe?
jrp
p.s. not into upgrade craze unless money is endless.
I found a great deal of help in the javascriptInMax.pdf, which i am sorry to have overlooked before.
Now if i create a multislider like this
panslider = this.patcher.newobject("user", "multiSlider", 20, 20, 120, 40, 0., 1., 1, 2936, 15, 0, 0, 2, 0, 0, 0);
the range attributes "0." & "1." get changed to "0." & "0." instead.
i found that out, when i used the inspector on the created multislider.
is that a bug or my inability?
thank you very much in advance for any help,
jrp
to answer my own question: it must be a bug.
sending
panslider.message('settype', 1);
panslider.message('setminmax', 0, 1);
right after panslider creation finally sets the panslider object to the desired operation. just to let you all know.
javascript in max IS terribly documented. if anyone or c74 needs help there: i'd be willing to assist.
jrp