Forums > Javascript

get comment or message box content within a js ?

August 21, 2010 | 9:01 am

I would need to get (and set) the content of (named) comment and message box within a js.
is it possible ?
couldn’t find info about it in the doc.
any help is very welcome !

thanks in advance

Mathieu


August 22, 2010 | 3:47 pm

Setting is as easy as sending a message to the named object with the set or message functions, but retrieving the current information is much more difficult. One idea is to script a [grab] object into place and connect it to a [message] box and back to a dedicated inlet of your [js] object. If you only need this to work in a patching environment you can even parse the JSON text of your patch as demonstrated in this article. However this won’t work with anything other than a maxpat file so if you need it to function in a standalone application this method will not work.


August 24, 2010 | 8:11 am

Thanks Luke for your reply.
unfortunately, this won’t help me much, because i need to get the content of a comment box, and grab can’t get it ; (and my js isn’t in the same patch…)
ok, I’ll find a workaround !

thanks !

Mathieu


September 2, 2010 | 8:56 am

I think you might ask C74 directly, and they should really adapt a bit max objects to your goals in next incremental max version, come on!, what you’re working on ( http://cycling74.com/forums/topic.php?id=28177 ) is just the future of max!


September 13, 2013 | 12:30 pm

Mathieu, did you ever resolve this issue? I am trying to do something similar, retrieving the text of a comment box with JS. Any info of your process or solution would be appreciated!


September 14, 2013 | 2:15 am

no, sorry, I never found a solution, and finally had to give up retrieving content of comment box.
:-(

M


September 14, 2013 | 8:38 am

One way to do this is to load up the patcher as JSON and then parse it for comment boxes.

Please excuse the roughly hacked out code – hopefully you will get the idea

var patcher_file = new File(this.patcher.filepath);
while (patcher_file.position != patcher_file.eof)
{
lines += patcher_file.readline();
}
patcher_file.close();
var parsed_patcher = JSON.parse(lines);
if (parsed_patcher["patcher"]["boxes"][0]["box"]["maxclass"] === "comment")
{
post(parsed_patcher["patcher"]["boxes"][0]["box"]["text"]);post();
}


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