Can't define patching_rect of object when creating it by script
Hello,
I'm generating objects in a patcher through JS (v8). I want to set their width with patching_rect.
This functions:
let comment = subpatcher.newdefault(50, 20, "comment", "@patching_rect", 50, 20, 380, 20);
But this doesn't:
let end_obj = subpatcher.newdefault(x_pos, y_pos, "buffer~", end_name, "@samps", end_dur_samps, end_chans, "@patching_rect", x_pos, y_pos, 380, 20);
it results in @patching_rect displayed as an attribute in the object but without any influence on the real patching rectangle of the object. Moving @patching_rect and its values just after "buffer" doesn't change anything.
Any idea on how to achieve this?
If I remember correctly, patching_rect attribute is available this way only for UI objects, but not regular Max objects.
I would do this instead:
let end_obj = this.patcher.newdefault(x_pos, y_pos, 'buffer~', 'mybuf', -1, end_chans, '@samps', end_dur_samps);
end_obj.size = [380, 20];
I also corrected the syntax: @samps takes only one argument, the size in samples. The number of channel has to be declared as the third argument of the object, after the buffer name and its duration in ms, hence the '-1' leaving the duration undefined (as we define it later on with @samps). This is definitely a weirdness specific to that object, as you would usually define the number of channels with an attribute, but it's not the case here.
Thank you TFL. However you are wrong when you state that @samps takes only one argument. It actually accepts two and allows to set the the number of channels with messages. Just try it.
TIL!
You're right, I just assumed it wouldn't work because I couldn't find any mention of that in the doc. How did you know it works?
I should stop assuming something isn't right because it's not in the doc.
There are many things which are not in the doc. You learn this kind of things through patchers made by others, sometimes even official help patchers/examples.
At some point in my life, when there wasn't a Max forum but only a mailing list, I spent some time every morning cutting and pasting code sent on the list and checking if there was something I ignored inside.
Yeah, I tend to do that too with patchs posted here or other places.
That's probably how I learnt about the settable-only MaxObj.size
property by the way. It's not listed in the js API doc and I don't remember seing it in the example patchers. The only way to find about it is to either find someone else's patch with that, or query MaxObj.getboxattrnames()
, see that size
is part of them, so that you know that you can use it as MaxObj.setboxattr('size', [w,h])
and finally just guess that you can do MaxObj.size = [w,h]
because why not.
Un-/poorly documented features is maybe one of the biggest drawbacks of Max for me. Not that the doc isn't great - it is, but it's somewhat incomplete. I really like the new User guide section though.
obj.size[x,y] functions with regular objects but I couldn't use it to enlarge message boxes or flonums.