Can I get all object's properties as JSON in stand-alone

Martin.Jirsak's icon

Hi all,

I'm making stand-alone application. In this application, the user can create some objects (encoders, sliders...). I want to be able to save and reopen this as a file. So the user could open (and use) his "preset" (with the encoders, sliders...), he had created.

How to do this, please? Thanks in advance.

Source Audio's icon

How would user crete objects in locked max -standalone patch ?
probably using scripting.
So you just need to store the scripts as text or whatever and read, load - execute them in the standalone

Martin.Jirsak's icon

Hi,

Thank you for your reply. Yes, the objects are created by using javascript.

The question is, how can I get all necessary data of the object (position, size, all attributes, etc.), so I can store them. Of course, I can ask every single object for the attributes "manually" one by one. But I was thinking, there is a direct way. The object is described by JSON in Max already. So my question is, how to save this JSON of the object and save/reload it.

Something like var mySliderAttributes = mySlider.box

Thank you

Source Audio's icon

If you create objects using scripting, then you also need to specify size and position of objects to create.So use that info and store it.

Martin.Jirsak's icon

Hi,

Yes, I know. But then I can allow the user to change the position, resize the object, change the attributes. I would need to track it all the time. I think, it would be much easier to ask the object for all attributes at once, at the moment, when the user is going to save his preset. Is this possible, please?

Thank you

Source Audio's icon

I have no idea, not really interested in such thing.
Maybe someone else could help you.

Dax's icon

Hi Martin,

I was curious when I read this question, and had a quick look, I think you could do it with pattrstorage and autopattr, I tested it a bit with the javascriptscripting patch and when you create the sliders in the patch they will be added to the storage. Then you write the storage to json, which you load into a dict so you can read the dict out with javascript to create the objects again when the user loads the app. I have not tested it yet nor wrote a JS script to read and create the objects, ( I just started to noodle around with N4M and JS, so not have a finished solution there. But have a look at the attached patch and play around by creating the objects )

also there is the example of the patchdescribe.js which might be also helpful>?

Also now I think of it. If you just want to recreate the objects write the created objects to another dict object that you read when you load, but I think the pattrstorage and autopattr method might be what you are looking for..

I am curious if you find something that works. Also I will have a go at it.

I think by reading a json file with objects and values you should be able to recreate them when a user is loading a preset.

Kind regards

Dax

Max Patch
Copy patch and select New From Clipboard in Max.